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
You use the Eval function
Also, VBScript is not strongly typed, so you can’t
Dim proc as String
so you would do something like this:
proc = “Call myFunction()”
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].
proc = "Call myFunction(arg)"
Thanks for your help.