views:

41

answers:

2

Hi, 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

+1  A: 

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
Luhmann
I'm having a hard time explaining this. Let me just write exactly my case, instead of an exampleI have made my own script. First it creates a control, let's say a panel, my code assign the background color, font and so on. The code can also make the control do some actions, for example change the color of another panel. So a script-line would look something like this:onClick:ChangeBackground-color:#ff44ff for Control-ID:myTestFormSo I try to add a handler to when the control is clicked, to run a sub ChangeBackground_Color(byRef newColor, byRef ControlID)I hope this make sense
Jacob Kofoed
wow, this is hard to explain, please feel to ask into this, fixing this would save my project :)
Jacob Kofoed
A: 

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)
Jason Rowe
Workes perfectly, thank you, but I'm not quite sure what you mean with "does not support multi-line statements" could you please explain this :)
Jacob Kofoed