Eval Method

 

Description

 

Evaluates an expression and returns the result.

 

PowerBASIC Syntax

 

METHOD Eval ( _

BYVAL bstrExpression AS STRING _

) AS VARIANT

 

Arguments

 

bstrExpression

BSTR. String containing the expression being evaluated.

 

Remarks

 

The context of the Eval method is determined by the object argument. If object is a module, the context is restricted to the named module. If object is the ScriptControl, the context is global.

 

Example [PowerBASIC]

 

#INCLUDE "MSSCRIPT.INC"

 

DIM pSc AS IScriptControl

DIM vRes AS VARIANT

 

' Creates an instance of the Microsoft Script Control

pSc = NEWCOM "MSScriptControl.ScriptControl"

' Set the language. It can be "VBScript" or "JScript"

pSc.Language = UCODE$("VBScript")

' In the following code, the ExecuteStatement method

' executes the statement and assigns the value 100 to the

' variable x. The next two lines use the Eval method

' to test the statements x = 100 and x = 100/2.

pSc.ExecuteStatement UCODE$("x = 100")

vRes = pSc.Eval(UCODE$("x = 100"))

MSGBOX STR$(CINT(VARIANT#(vRes)))

vRes = pSc.Eval(UCODE$("x = 100/2"))

MSGBOX STR$(CINT(VARIANT#(vRes)))

 

Valid XHTML 1.0 Transitional