-
July 12th, 2002, 12:23 AM
#1
Eval Function
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
pls Help
thank u
-
July 12th, 2002, 01:03 AM
#2
You can call the eval funtion through the scriptcontrol. You can choose the language of the scriptcontrol to be either JScript or VBScript.
Code:
Scriptcontrol1.Eval("var mydate = new Date();")
'or
Scriptcontrol1.Eval("mydate = Now()")
-
July 12th, 2002, 01:21 AM
#3
:(
i have written followiing code but the value of mysdate remains blank
Dim mydate
ScriptControl1.Eval ("mydate = Now()")
MsgBox mydate
-
July 12th, 2002, 01:49 AM
#4
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:
Code:
' class module called Class1
Public MyDate
Public Sub ShowDate()
Msgbox MyDate
End Sub
' form
Dim MyClass As New Class1
ScriptControl1.AddObject "MyClass", MyClass
ScriptControl1.ExecuteStatement "MyClass.MyDate = Now()"
Msgbox MyClass.MyDate
' or
ScriptControl1.AddObject "MyClass", MyClass, True
ScriptControl1.ExecuteStatement "MyDate = Now()" ' not using the class now
Msgbox MyClass.MyDate
' use of eval
Msgbox ScriptControl.Eval("1+1") ' should give 2
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.
Code:
ScriptControl1.ExecuteStatement "MyObject.ShowDate"
' or just
ScriptControl1.ExecuteStatement "ShowDate"
' depending on how you added the object
-
November 2nd, 2004, 04:44 PM
#5
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 !
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
|