Add a Handler with the procedure name in a string

g000we

Member
Joined
Mar 22, 2007
Messages
8
Programming Experience
1-3
Hello,

Does anyone here know how to call a procedure named in a string..

I have..

sub doThisClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
msgbox "Clicked!"
end sub

dim nameOfProc as String
nameOfProc = "doThisClick"
dim btnNew as new button

addHandler btnNew.click, addressOf nameOfProc

AddressOf says "AddressOf operand needs to be the same name as the method (without parenthenses)"..

Aih?

Any help would be grand!

Regards,

g000we
 
Reflection is the only way to reference instances from string literals (in this context, not thinking about looping and checking names...), research the topic if you feel like, but it is very rare in normal code that you need it. A delegate or interface may be other options if you need more dynamics in code to allow different methods/instances to be used in different cases.
 

Latest posts

Back
Top