VBS - How to call function in a variable

My co-worker is writing a VB script and she wants to call a function that is stored in a string, but she doesn’t want to write a long switch statement.

I told her it was easy to do in Perl but she wasn’t amused. Any ideas?

This doesn’t work:

dim proc as string

proc = myFunction
Call proc

You use the Eval function

Also, VBScript is not strongly typed, so you can’t

Dim proc as String

it’s just

Dim proc

so you would do something like this:

Dim proc

proc = “Call myFunction()”

Call Eval(proc)

MSDN - Use this instead of SDMB next time…

Well of course I tried MSDN, but I couldn’t come up with the right search terms. [I guess I should have just browsed the list of functions, but I didn’t think of that.]

Eval didn’t work though – we kept getting syntax errors. She had to use Execute [which was at the bottom of the Eval help page you linked to].

This worked:

dim proc

proc = "Call myFunction(arg)"
Execute proc

Thanks for your help.