|
-
December 2nd, 1999, 02:45 AM
#1
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
-
December 2nd, 1999, 03:01 AM
#2
Re: Sub/Function stored in Variable possible?
you can use the Microsoft Script control to do that. This OCX has an Eval method.
-
December 2nd, 1999, 04:46 AM
#3
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?
-
December 2nd, 1999, 01:59 PM
#4
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]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|