The following code illustrates the use of the
Eval method.
' ########################################################################################
' Microsoft Script Control example.
' 2008 José Roca - Use at your own risk.
' ########################################################################################
' SED_PBWIN ' Use the PBWIN compiler
#COMPILE EXE
#DIM ALL
#INCLUDE "MSSCRIPT.INC"
' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN
LOCAL pSc AS IScriptControl
LOCAL vRes AS VARIANT
' Creates an instance of the Microsoft Script Control
pSc = NEWCOM "MSScriptControl.ScriptControl"
IF ISNOTHING(pSc) THEN
MSGBOX "Error creating an instance of the Microsoft Script Control"
EXIT FUNCTION
END IF
TRY
' 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))) ' -1 - True (in COM, True is -1, not 1)
vRes = pSc.Eval(UCODE$("x = 100/2"))
MSGBOX STR$(CINT(VARIANT#(vRes))) ' 0 - False
CATCH
MSGBOX MSScriptControl_GetErrorInfo(pSc, OBJRESULT)
END TRY
' Releases the interface
pSc = NOTHING
END FUNCTION
' ========================================================================================