Reputation: 77
it seems that adding for example a button Dim myButton as New Button
and then addHandler to mySub("lol", 255)
is not possible.
Where mySub
is Shared Sub MySub(byRef myString as string, myInteger as Integer)
So: addHandler myButton.click, addressOf mySub("lol", 255)
- returns an error saying it does not work with parentheses or whatever.
I somehow see why this might not be possible, so I'm looking for a work-around on this problem.
Please help _jakeCake
Upvotes: 1
Views: 6206
Reputation: 6286
Maybe you could look into using a lambda expression when you add the event. When using lambda's in VB.NET the function must return a value and does not support multi-line statements.
Dim myButton As New Button
AddHandler myButton.Click, Function(senderObj, args) myFunc("lol", 255)
Upvotes: 0
Reputation: 3890
First of all the syntax for AddHandler would be:
AddHandler myButton.click, AddressOf mySub
Secondly the signature of the eventhandler procedure must match the signature of the event like so:
Private Sub myButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
[...]
End Sub
Upvotes: 2