1

I am trying to find a way to call a function by typing its name in a text box and clicking a button , i have 417 functions and they don't take any variables

for example i want to type in a textbox

listproducts

and click a button

then listproducts() will get called.

is it possible to do such things without using select case or if statements? or is it possible to assign a string name to a function and call it by that name?

1

1 Answer 1

4

You need to use reflection. Assuming the the functions you want to call are all static methods on a class called Foo you can do something like this.

Dim functionName as String = "listproducts"
Dim fooType As System.Type = GetType(Foo)
Dim Method As System.MethodInfo = fooType.GetMethod(functionName)
Method.Invoke(Nothing, Nothing)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.