Sub/Function stored in Variable possible?
Hi,
Is it possible (and how) to store a function call in a variable, then "evaluate" the variable? In other words, can I do the following:
function test (x,y)
test = x + y
end function
myVar = "test(1,2)"
myResult = evaluate(myVar)
Now, myResult should be 3.
If this is not possible in VB, is there a way around this? Some tricks, maybe?
Please help.
Thanks
Re: Sub/Function stored in Variable possible?
you can use the Microsoft Script control to do that. This OCX has an Eval method.
Re: Sub/Function stored in Variable possible?
I have try to put this control in my form and perform ScriptControl1.Eval("test(1,2)") and it doesn't work. What i did wrong?
Re: Sub/Function stored in Variable possible?
If you have VB6 then you can use CallByName function. But you would have to have your functions in a Class Module (not regular mudule) because CallByName function has first parameter as an object.
Syntax: CallByName(object, procname, calltype,[args()])
Example:
iSum = CallByName(Class1, "Multiply", VbMethod, 5, 5)
MsgBox iSum
Assuming that I have function Multiply in calss called Class1.
Regards,
Serge
Software Developer
[email protected]