Author Topic: IScriptControl.Eval Method  (Read 3874 times)

0 Members and 1 Guest are viewing this topic.

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2530
  • User-Rate: +209/-0
  • Gender: Male
IScriptControl.Eval Method
« on: July 15, 2008, 12:47:27 AM »

The following code illustrates the use of the Eval method.

Code: [Select]
' ########################################################################################
' 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
' ========================================================================================
« Last Edit: August 07, 2011, 08:02:04 AM by José Roca »