I'm getting a "...does not have a signature compatible with delegate..." message when trying to pass a parameter to a method. Can someone advise me on what I'm doing wrong?
Private Sub btnSubmit_Click(sender As Object, e As RoutedEventArgs) Handles btnSubmit.Click
Step6Click("btnSubmit")
End Sub
Private Sub Step6Click(whereFrom As String)
Initially, no error is flagged but when the application is built, that's when the error occurs.
I changed ("btnSubmit") to ("xxx") thinking there was some conflict with passing "btnSubmit" when there was a button named the same. Still get the error.
If I take out the parameter all together, then no error occurs, but I need to know in Step6Click where the call came from.
I can bypass the error by creating a property or variable called "whereFrom". However I'd like to understand why this is an error.
Complete error message:
Error 33 Method 'Private Sub Step6Click(whereFrom As String)' does not have a signature compatible with delegate
'Delegate Sub RoutedEventHandler(sender As Object, e As System.Windows.RoutedEventArgs)'.
Thanks.
If Step6Click is an event handler that you are trying to hook up to the Click event of a Button in your XAML markup it should have the following signature or no parameters at all:
Private Sub Step6Click(sender As Object, e As RoutedEventArgs)
End Sub
You could create another method that you call from both your event handlers, i.e. just create another method with a different name, e.g.:
Private Sub btnSubmit_Click(sender As Object, e As RoutedEventArgs) Handles btnSubmit.Click
Step6ClickMethod("btnSubmit")
End Sub
Private Sub Step6Click(sender As Object, e As RoutedEventArgs)
Step6ClickMethod("btnSubmit")
End Sub
Private Sub Step6ClickMethod(ByVal whereFrom As String)
End Sub
Related
I wrote a code to demonstrate the issue:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
doSomething()
End Sub
Dim controlArr() As Object = {NumericUpDown1, NumericUpDown2, NumericUpDown3, NumericUpDown4, CheckBox1, CheckBox2, CheckBox3, CheckBox4}
Private Sub doSomething()
Dim testStr As String = ""
For Each control In controlArr
Select Case control.GetType
Case GetType(NumericUpDown)
control.value = 1
Case GetType(CheckBox)
control.checked = True
End Select
Next
End Sub
End Class
When I run the code I receive Null Referenece Exception "Object reference not set to an instance of an object", the error disapears when I declare the controlArr array inside DoSomething subroutine. Anyway I would prefer having it declared outside since I am using it in many functions. I would like to understand it better so if you provided me with a topic I could read up on I would be very grateful. Thank you very much for your help.
The issue is that declarations are processed before the constructor. That means that this line:
Dim controlArr() As Object = {NumericUpDown1, NumericUpDown2, NumericUpDown3, NumericUpDown4, CheckBox1, CheckBox2, CheckBox3, CheckBox4}
is executed before the code that creates all the controls on the form and assigns them to those fields. As such, all the fields are Nothing at the time that code is executed and so your array contains a whole lotta nothin'. There's no issue creating objects to initialise fields like that and that code does successfully create an array. It's just that you are implicitly setting every element of that array to Nothing so that's what you get to use later on.
If you want to reference any control then you have to wait until after the form's controls are created. That means, at the earliest, after the call to InitializeComponent in the constructor. More generally, you should do it in the Load event handler, e.g.
Dim controlArr As Object()
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Form1.Load
controlArr = {NumericUpDown1, NumericUpDown2, NumericUpDown3, NumericUpDown4, CheckBox1, CheckBox2, CheckBox3, CheckBox4}
End Sub
I have attached code for reference. I am trying to create database for my project details. I have currently 2 forms:
main form
project detail form
Main form used to switch various forms
Project detail forms are meant for add / edit / load project details
My main form in visual basic look like this.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Bt_Project_Details_Click(sender As Object, e As EventArgs) Handles Bt_Project_Details.Click
Me.Hide()
Project_Details_Form.Show()
End Sub
End Class
My project detail form look like this.
Public Class Project_Details_Form
Private Sub Project_Details_Form_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Project_Data_Set.Project_Data_Table' table. You can move, or remove it, as needed.
Me.Project_Data_TableTableAdapter.Fill(Me.Project_Data_Set.Project_Data_Table)
End Sub
Private Sub Bt_Load_Project_Click(sender As Object, e As EventArgs) Handles Bt_Load_Project.Click
End Sub
Private Sub Bt_Cancel_Click(sender As Object, e As EventArgs) Handles Bt_Cancel.Click
Me.Hide()
Form1.Show()
End Sub
Private Sub BindingNavigatorAddNewItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorAddNewItem.Click
Project_Data_TableBindingSource.AddNew()
End Sub
Private Sub Project_Data_TableBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles Project_Data_TableBindingNavigatorSaveItem.Click
Me.Validate()
Me.Project_Data_TableBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.Project_Data_Set)
End Sub
Private Sub BindingNavigatorDeleteItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorDeleteItem.Click
Project_Data_TableBindingSource.RemoveCurrent()
End Sub
Private Sub FillByToolStripButton_Click(sender As Object, e As EventArgs)
Try
Me.Project_Data_TableTableAdapter.FillBy(Me.Project_Data_Set.Project_Data_Table)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
End Sub
End Class
Now I am facing a few problems:
Whenever I run the program, try to enter first entry data being saved but with empty value. The data enter next time being stored properly. How can make my first entry visible?
In below code:
Private Sub BindingNavigatorAddNewItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorAddNewItem.Click
Project_Data_TableBindingSource.AddNew()
End Sub
I am using AddNew(). This working fine, but problem is even I don't enter data like date, name kept empty, data recorded in their position is store empty only. I would like to say if any of project data set is empty give error message (since it mandatory for user to enter those data)
Is there any other method where i can assign value individually .
Like my Project database contain project name, customer name etc. if i say new button pressed clear all field. Once form filled individual value being record once save button pressed
Private Sub BindingNavigatorAddNewItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorAddNewItem.Click
Project_Data_TableBindingSource.AddNew()
End Sub
This is my first post on stackoverflow so please hang with me. I am attempting to update an access database using VB.NET. Using the following series of videos (starting with this one), we have been able to properly use our form to save new data into the access database.
https://www.youtube.com/results?search_query=vb.net+ms+access+database+tutorial+1+%23+add+new+remove+save+data+in+database+using+vb.net
However, when we start up the form again after opening up access to make sure the updates have occurred (which they always do), none of our changes are there. And when we open up access again the changes we made that showed up in the access database are gone, and the access database goes back to its original state (the state it was when we linked it to visual studio in the first place).
Below is the code we have so far, we appreciate any help you can give us!
Thanks.
Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Private Sub Sheet1BindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles Sheet1BindingNavigatorSaveItem.Click
Me.Validate()
Me.Sheet1BindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(MIS275_Small_BusinessDataSet)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'MIS275_Small_BusinessDataSet.Sheet1' table. You can move, or remove it, as needed.
Timer1.Start()
Me.Sheet1TableAdapter.Fill(MIS275_Small_BusinessDataSet.Sheet1)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Sheet1BindingSource.AddNew()
End Sub
Private Sub Save_Click(sender As Object, e As EventArgs) Handles Save.Click
Try
Sheet1BindingSource.EndEdit()
Sheet1TableAdapter.Update(MIS275_Small_BusinessDataSet.Sheet1)
MessageBox.Show("Data Saved")
Catch ex As Exception
MessageBox.Show("Error")
End Try
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim count As Integer
count = Sheet1BindingSource.Count
End Sub
End Class
Am still learning VB and database but I have a little problem. My codes works but when I
try to look into the database I don't find all what are been saved, how do I rectify it? and also the edit and delete. thanks
Here is my code:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'ItemsDataSet.Items' table. You can move, or remove it, as needed.
Me.ItemsTableAdapter.Fill(Me.ItemsDataSet.Items)
'TODO: This line of code loads data into the 'ItemsDataSet.Items' table. You can move, or remove it, as needed.
Me.ItemsTableAdapter.Fill(Me.ItemsDataSet.Items)
'TODO: This line of code loads data into the 'ItemsDataSet.Items' table. You can move, or remove it, as needed.
Me.ItemsTableAdapter.Fill(Me.ItemsDataSet.Items)
End Sub
Private Sub ItemsDataSetBindingSource_CurrentChanged(sender As Object, e As EventArgs)
End Sub
Private Sub btnedit_Click(sender As Object, e As EventArgs) Handles btnedit.Click
ItemsBindingSource.EndEdit()
ItemsTableAdapter.Update(ItemsDataSet.Items)
MsgBox("Saved")
End Sub
Private Sub btadd_Click(sender As Object, e As EventArgs) Handles btnadd.Click
ItemsBindingSource.AddNew()
MsgBox("Added Successfully")
End Sub
Private Sub btndelete_Click(sender As Object, e As EventArgs) Handles btndelete.Click
ItemsBindingSource.RemoveCurrent()
MsgBox("Item Deleted")
End Sub
Private Sub btnexit_Click(sender As Object, e As EventArgs) Handles btnexit.Click
Close()
End Sub
Private Sub btnprevious_Click(sender As Object, e As EventArgs) Handles btnprevious.Click
ItemsBindingSource.MovePrevious()
End Sub
Private Sub btnnext_Click(sender As Object, e As EventArgs) Handles btnnext.Click
ItemsBindingSource.MoveNext()
End Sub
End Class
You probably have your MDB (ACCDB) file included in your project files.
If you check the properties associated with this project file you will find one named Copy to Output Directory. Set this to Copy Always.
Also your connection string contains the shortcut Data Source = "|DataDirectory|\yourdb.mdb"
If this scenario is correct, then you start your application and the MDB / ACCDB file is copied from the original location to the BIN\DEBUG directory.
You insert your data there without error. When you stop the debug session to fix errors or other problems you restart your application and the fresh copy (but empty) of your db is copied again in the output directory.
To fix this, set the property to Copy Never or change your connection string to point to a fixed location.
im just wondering on how can i pass value of a variable to another form from a different form
I have a form called frmSearch then I have another form called frmMain from frmSearch i have a varible A which is publicly declared and i wanted the value of A to frmMain i've tried the following
frmMain
dim B = frmSearch.A
but everytime i checked the value of B it always returns a blank string
also when i checked the value of frmSearch.A it also returns nothing even though it returns a value when i checked it in frmSearch
please help im really stuck
thanks in advance
Accessing a field of a form shouldn't be a problem. Just make sure that at the time you are reading the field it is already assigned.
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim form = New Form2
Debug.Assert(form.A Is Nothing)
form.ShowDialog()
Debug.WriteLine(form.A(0))
End Sub
End Class
Public Class Form2
Public A As String()
Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
A = {"abc", "aaa"}
End Sub
End Class