John
John

Reputation: 6612

Passing parameters to dynamic named function

I want to call a function with a dynamic name, which can be done with Eval:

fName = "TestFunction"
Call Eval(fName)

This works great, but how do I pass parameters to this function call? Something like this doesn't work:

Call Eval(fName)(Param1, Param2)

Upvotes: 0

Views: 569

Answers (2)

MC ND
MC ND

Reputation: 70923

If you use Eval you need to prepare the code to execute

Call Eval(fName & "(" & Param1 & "," & Param2 & ")" )

What you are trying needs GetRef

Call GetRef(fName)(Param1, Param2)

Upvotes: 3

Bond
Bond

Reputation: 16311

Function Add(int1, int2)
    Add = int1 + int2
End Function

intSum = Eval("Add(1, 2)")
' or...
intSum = Eval("Add(" & intParam1 & ", " & intParam2 & ")")

Upvotes: 0

Related Questions