July 12th, 2002, 01:23 AM
we have eval function in Jscript
is there anything we can use in vb
The eval function allows dynamic execution of JScript source code. For example, the following code creates a new variable mydate that contains a Date object:
eval("var mydate = new Date();");
The code passed to the eval method is executed in the same context as the call to the eval method.
eval function is there is vbscript
but i don't know how to run vbscript in VB
July 12th, 2002, 02:03 AM
You can call the eval funtion through the scriptcontrol. You can choose the language of the scriptcontrol to be either JScript or VBScript.
Scriptcontrol1.Eval("var mydate = new Date();")
Scriptcontrol1.Eval("mydate = Now()")
July 12th, 2002, 02:21 AM
i have written followiing code but the value of mysdate remains blank
ScriptControl1.Eval ("mydate = Now()")
July 12th, 2002, 02:49 AM
Appearantly, you cannot use the scriptcontrol like that. First of all, to something like that, you need to use the ExecuteStatement method rather than the Eval function.
Secondly, you can only create a bridge between the control and the program by using objects and the AddObject method of the control.
Something like this:
If you create public subs/functions/properties in the class, you will be able to call them on the very same way from the scriptcontrol.
' class module called Class1
Public Sub ShowDate()
Dim MyClass As New Class1
ScriptControl1.AddObject "MyClass", MyClass
ScriptControl1.ExecuteStatement "MyClass.MyDate = Now()"
ScriptControl1.AddObject "MyClass", MyClass, True
ScriptControl1.ExecuteStatement "MyDate = Now()" ' not using the class now
' use of eval
Msgbox ScriptControl.Eval("1+1") ' should give 2
' or just
' depending on how you added the object
November 2nd, 2004, 04:44 PM
Re: Eval Function
I dont know why you have to write so many lines of Code. For me, ScriptControl1.Eval("Date") and ScriptControl1.Eval("2 + 4") worked just fine !
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!