Reputation: 822
When I place Set_Symbol()
in my code it give me two errors.
Errors:
Argument not specified for parameter 'e' of 'Private Sub Set_Symbol(sender As Object, e As System.EventArgs)'. d:\documents\visual studio 2010\Projects\Math Game\Math Game\frmindex.vb
Argument not specified for parameter 'sender' of 'Private Sub Set_Symbol(sender As Object, e As System.EventArgs)'. d:\documents\visual studio 2010\Projects\Math Game\Math Game\frmindex.vb
This is what Set_Symbol is:
Private Sub Set_Symbol(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles rbnaddition.Click, rbnsubtraction.Click, rbnmultiplication.Click, rbndivision.Click
Dim rbn As RadioButton
rbn = CType(sender, RadioButton)
symbol = rbn.Tag
End Sub
This is how I called it:
Private Sub frmindex_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
symbolrbn(0) = rbnaddition
symbolrbn(1) = rbnsubtraction
symbolrbn(2) = rbnmultiplication
symbolrbn(3) = rbndivision
Set_Symbol()
Populate()
End Sub
Why is it throwing this error?
Upvotes: 1
Views: 37500
Reputation: 1
Imports System.Data.SqlClient
Public Class Form1
'Dim con As New SqlConnection("Data Source=admin-pc\sqlexpress;Initial Catalog=employee;Integrated Security=True")
Dim con As SqlConnection
Dim cmd As SqlCommand
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
con = New SqlConnection("Data Source=admin-pc\sqlexpress;Initial Catalog=employee;Integrated Security=True")
con.Open()
cmd = New SqlCommand("insert into emp_table values('" &TextBox1.Text "')",con)
cmd.ExecuteNonQuery()
con.Close()
End Sub
End Class
Upvotes: -1
Reputation: 29244
Notice the Sub
definition requires two parameters sender
and e
and you have not supplied it with any during Load
. Luckily you already have a sender
and e
defined, if you chain the event. So you could directly handle the Load
event like the radiobutton actions, or call it with the two parameters.
Private Sub Set_Symbol(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles rbnaddition.Click, rbnsubtraction.Click, rbnmultiplication.Click, _
rbndivision.Click, MyBase.Load
Dim rbn As RadioButton
rbn = CType(sender, RadioButton)
If rbn IsNot Nothing then
symbol = rbn.Tag
End If
End Sub
or
Private Sub frmindex_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
symbolrbn(0) = rbnaddition
symbolrbn(1) = rbnsubtraction
symbolrbn(2) = rbnmultiplication
symbolrbn(3) = rbndivision
Set_Symbol(rbnaddition, Nothing) 'Default to '+' symbol
Populate()
End Sub
Upvotes: 0
Reputation: 460108
Set_Symbol()
in frmindex_Load
won't compile because the method takes two parameters but you are trying to call it without parameters.
You shouldn't mix event-handler code with code that is manually called because they are two different things. If you need to call a method from an event-handler as well as manually from somewhere else, you should provide a method that takes the appropriate parameters(or none if not needed) and call that from both locations.
If you actually wanted to set the Tag
for each RadioButton, you should provide a method that takes no parameter and sets the Tag property for each RadioButton.
I assuming that the handler should read the Tag instead of set it.
Upvotes: 2
Reputation: 21855
You should call Set_Symbol(sender,e)
to make it compile
Upvotes: 1