Click to See Complete Forum and Search --> : Sub/Function stored in Variable possible?


ETT
December 2nd, 1999, 01:45 AM
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

Lothar Haensler
December 2nd, 1999, 02:01 AM
you can use the Microsoft Script control to do that. This OCX has an Eval method.

Sigal Laniado
December 2nd, 1999, 03:46 AM
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?

Serge_D
December 2nd, 1999, 12:59 PM
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
Serge_Dymkov@vertexinc.com