I'm using VBScript and I am wondering if is there any way to call a function name stored in string variable?
Here is my attempt?
a = "b"
sub b()
msgbox "c"
end sub
a()
But it always result in an error
Type mismatch 'a'
The correct answer is: Use GetRef() as in:
Function F(p)
F = p + p
End Function
Dim FP : Set FP = GetRef("F")
WScript.Echo FP("a")
WScript.Echo FP(123)
Output:
aa
246
Seems like e.g. this should work:
Dim a
a = "Call b()"
Eval(a)
Sub b
' Do stuff
End Sub
Dim x
Sub b
print "xxx"' Do stuff
End Sub
x = "call b()"
Execute(eval("x"))