newObjects-logo.gif (1024 bytes) ScriptManager2 reference
script property

read only

Returns dynamically created IDispatch interface of the running script

variable = object.script

variable object Running script as dispatch interface
object ScriptManager2 Previously created ScriptManager2 object

Remarks:

Through this property global methods of the currently running script can be called. Through the property script looks just like a component with methods corresponfding to the global functions/subroutines defined in the script.

Sample:

// Create the component
var scph = new ActiveXObject("newObjects.Scphost.ScpMan2");
// Add scripting host WScript object as namespace to the ScriptManager2
// with name "world"
scph.Add("world",WScript);
// Load VBScript engine
scph.LoadEngine("VBSCRIPT");

// Define the VBScript code 
var str = "Sub MyMethod(param)\n";
str    += "        world.Echo \"Parameter is:\" & param\n";
str    += "End Sub";
// Add the code
scph.AddText(str);
// Run the script
scph.Run();
// Call the subroutine
scph.script.MyMethod("Hello World !");

The output will be:

Parameter is:Hello World!

Global variables of the script can be accessed as a properties.

Take care for the parameters passed to the script methods. For example in JScript exact match is not required but in other languages like VBScript parameters must match the function/sub declaration.

See also:

C++ Helper SCPHOSTCLNT::GetScriptDispatch method

newObjects Copyright newObjects 2001-2005