Calling procedure by string value (Resolved)
I have a table and in it I have over 100 procedure names, the procedures themselves are part of the applicaiton. Is it possible to get the value from the table and call the procedure accordingly without using any case or if statments. i.e. a string, Mystring will have a value Proc1 and using this value I will call Proc1.
Re: Calling procedure by string value
You would need to use reflection.
VB Code:
'Get the type of the current instance.
Dim myType As Type = Me.GetType()
'Get a MethodInfo object by specifying the name of the method.
Dim myMethodInfo As Reflection.MethodInfo = myType.GetMethod("MethodName")
'Call the method on the current instance with no arguments.
myMethodInfo.Invoke(Me, Nothing)
This would be equivalent to:
Re: Calling procedure by string value
Thanks, I will read a little on reflection and give it a try.
Re: Calling procedure by string value
Since this thread isn't marked as resolved, I will add Delegates. Give a search for Delegates and you will find additional information about them.