Author Topic: IScriptControl.Reset Method  (Read 4397 times)

0 Members and 1 Guest are viewing this topic.

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2517
  • User-Rate: +209/-0
  • Gender: Male
IScriptControl.Reset Method
« on: July 15, 2008, 12:33:56 AM »

The following code illustrates the use of the Reset 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 strScript AS STRING
   LOCAL vRes AS VARIANT
   LOCAL vPrms AS VARIANT
   LOCAL rgsabound AS SAFEARRAYBOUND
   LOCAL psa AS DWORD
   LOCAL vPrm AS VARIANT
   LOCAL vEmpty AS VARIANT
   LOCAL ix AS LONG

   ' Create 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")
      ' Deactivate the user interface
      pSc.AllowUI = %VARIANT_TRUE
      ' Set the UseSafeSubset property to True
      pSc.UseSafeSubset = %VARIANT_TRUE
      ' Make an script
      strScript = "Sub Main" & $CRLF & _
                  "   MsgBox ""Hello everybody.""" & $CRLF & _
                  "End Sub"
      pSc.AddCode UCODE$(StrScript)
      ' Create a safearray with zero elements
      ' Note: Parameters are passed as a safearray by reference. Therefore, we
      ' need to always pass a valid pointer.
      rgsabound.lLBound = 1
      rgsabound.cElements = 0
      psa = SafeArrayCreate(%VT_VARIANT, 1, rgsabound)
      ' Run the script
      vRes = pSc.Run(UCODE$("Main"), psa)
      ' Reset the script control
      pSc.Reset
      ' Try to run the script again
      vRes = pSc.Run(UCODE$("Main"), psa)
   CATCH
      MSGBOX MSScriptControl_GetErrorInfo(pSc, OBJRESULT)
   FINALLY
      ' Destroy the safearray
      IF psa THEN SafeArrayDestroy psa
      psa = %NULL
   END TRY

   ' Releases the interface
   pSc = NOTHING

END FUNCTION
' ========================================================================================
« Last Edit: August 07, 2011, 08:04:05 AM by José Roca »