1

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

Jacob Kofoed
  • 77
  • 4
  • 9

2 Answers2

2

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
  • 3,860
  • 26
  • 33
  • I'm having a hard time explaining this. Let me just write exactly my case, instead of an example I 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:myTestForm So 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 Mar 07 '10 at 22:56
  • wow, this is hard to explain, please feel to ask into this, fixing this would save my project :) – Jacob Kofoed Mar 07 '10 at 22:57
0

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
  • 6,216
  • 1
  • 33
  • 36
  • 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 Mar 08 '10 at 16:25