Calling a function name stored in a string variable?

I am using VBScript and I am wondering if there is a way to call the function name stored in a string variable?

Is this my attempt?

a = "b" sub b() msgbox "c" end sub a() 

But this always leads to an error

Type A mismatch

0
source share
3 answers

Looks like for example this should work:

 Dim a a = "Call b()" Eval(a) Sub b ' Do stuff End Sub 
+4
source

Correct answer: 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 
+12
source
 Dim x Sub b print "xxx"' Do stuff End Sub x = "call b()" Execute(eval("x")) 
-2
source

Source: https://habr.com/ru/post/945581/


All Articles