CodeObject Property |
Description
Returns an object that is used to call public members of a specified module. Read-only.
PowerBASIC Syntax
Remarks
The names of public members of a module are those provided by a programmer using the ScriptControl in an application.
Example [PowerBASIC]
#INCLUDE "MSSCRIPT.INC"
DIM pSc AS IScriptControl DIM strScript AS STRING DIM pModules AS IScriptModuleCollection DIM pModule AS IScriptModule DIM pCodeObject AS IDispatch DIM oCodeObject AS DISPATCH DIM vPrm1 AS VARIANT DIM vPrm2 AS VARIANT 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") ' *** Add a new module and a procedure and call it ' using PB automation *** ' Get a reference to the modules collection pModules = pSc.Modules IF ISTRUE ISOBJECT(pModules) THEN pModule = pModules.Add(UCODE$("MyModule")) IF ISTRUE ISOBJECT(pModule) THEN ' Add a procedure to the module strScript = "Function Multiply(vPrm1, vPrm2)" & $CRLF & _ " Multiply = vPrm1 * vPrm2" & $CRLF & _ "End Function" pModule.AddCode UCODE$(strScript) ' Get the dispatch interface of the module pCodeObject = pModule.CodeObject IF ISTRUE ISOBJECT(pCodeObject) THEN oCodeObject = pCodeObject pCodeObject = NOTHING END IF ' Use PB automation to call the procedure vPrm1 = 6 : vPrm2 = 5 OBJECT CALL oCodeObject.Multiply(vPrm1, vPrm2) TO vRes MSGBOX "Result: " & STR$(VARIANT#(vRes)) END IF END IF
|