1

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?

2
  • Do you actually call it manually? Can you show us the code you placed it in? Commented Aug 25, 2011 at 10:32
  • Notice the Sub definition requires two parameters sender and e and you have not supplied it with any during Load. Commented Aug 25, 2011 at 10:51

4 Answers 4

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

... and from the looks of it, the manual call isn't necessary at all in the frmindex_Load() method since it's an event handler for a bunch of other things.
In fact, no exception is thrown, this is misleading. Rather, the compiler complains.
@Konrad: adjusted accordingly.
1

You should call Set_Symbol(sender,e) to make it compile

2 Comments

But what for? The (sender, e) of the form's Load event seem irrelevant to the Set_Symbol handler.
If you're calling directly an event handler you should set the same parameters and event handler will do. You really should call Set_Symbol(rbnaddition,EventArgs.Empty) for example.
0

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

Comments

-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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.