Invoke a SUB named in a string

John H.

Member
Joined
Mar 31, 2008
Messages
14
Programming Experience
Beginner
I need to invoke a SUB that is named in a string object. Is this possible?

' Delcare the return code variable
DIM strReturnCode as string
' Declare the sub name
DIM strSubName as string = "MySubName"
' Invoke the sub, passing a return code parameter
strSubName(strReturnCode)

the SUB is in a different module

Thanks
 
Hello,

You can make use of CallByName() Function of .Net framework.

Let's say we have two SUB defined, Sub1 and Sub2. Now we want to call
either of these methods dynamically by inputting the name of the Sub in
a textbox. For this, we can use the following code.

CallByName(Me, TextBox1.Text.ToString(), CallType.Method, Nothing)

For more information, you can visit the given web link:

http://msdn.microsoft.com/en-us/library/chsc1tx6.aspx

I hope this will help.

Regards,

Allen Smith
ComponentOne LLC
www.componentone.com
 
Back
Top