Deciding what function to use at runtime in VB

Good coding practice in VBA (or Visual Basic itself) suggests that you should use functions and subroutines rather than one big long list of code. However, sometimes you may not know in advance the name of the procedure you want to call. This is a problem because you can't use a variable to call a function.

Actually, you can. Just use the "run" method. As an illustration of how it works, the following 2 bits of code do the same thing, both calling the function func1. The difference is that in the second one we didn't have to decide on the function to run before the code started running.

dim result as integer, firstparameter as integer, secondparameter as integer
result = func1(firstparameter, secondparameter)

and

dim result as integer, firstparameter as integer, secondparameter as integer
dim functiontorun as string
functiontorun = "func1"
result = run(functiontorun, firstparameter, secondparameter)