Run Method

 

Description

 

Runs a specified procedure.

 

PowerBASIC Syntax

 

METHOD Run ( _

BYVAL bstrProcedureName AS STRING, _

BYVAL Parameters AS DWORD _

) AS VARIANT

 

Arguments

 

bstrProcedureName

String name of the procedure to run.

Parameters

A safearray of variants containing any parameters for the procedure being run.

 

Remarks

 

There are two ways to run a procedure:

 

Use the Run method. To do this, specify the procedure name as a string. This is useful when the names of the procedures are not known in advance.

 

Use the CodeObject and call it directly. This is useful when you know the names of all procedures ahead of time.

 

Example [PowerBASIC]

 

#INCLUDE "MSSCRIPT.INC"

 

DIM pSc AS IScriptControl

DIM strScript AS STRING

DIM vRes AS VARIANT

DIM vPrms AS VARIANT

DIM rgsabound AS SAFEARRAYBOUND

DIM psa AS DWORD

DIM vPrm AS VARIANT

DIM vEmpty AS VARIANT

DIM ix AS LONG

 

' Create an instance of the Microsoft Script Control

pSc = NEWCOM "MSScriptControl.ScriptControl"

 

TRY

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

  pSc.Language = UCODE$("VBScript")

  ' Deactivate the user interface

  pSc.AllowUI = %VARIANT_TRUE

  ' Set timetout to 1 second

  pSc.TimeOut = 1000

  ' Make a script

  strScript = "Sub Main" & $CRLF & _

              "   For i = 1 to 10000000" & $CRLF & _

              "      x = x + i" & $CRLF & _

              "   Next" & $CRLF & _

              "   Msgbox ""Done"" " & $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)

CATCH

  MSGBOX MSScriptControl_GetErrorInfo(pSc, OBJRESULT)

FINALLY

  ' Destroy the safearray

  IF psa THEN SafeArrayDestroy psa

END TRY

 

Valid XHTML 1.0 Transitional