DIAdem Help

Method: ExecuteGlobal for VBS

  • Updated2024-09-12
  • 1 minute(s) read

Method: ExecuteGlobal for VBS

Executes instructions in the global namespace. You can use this to include other scripts in your script. DIAdem also covers the functions ScriptInclude and ScriptStart that offer a similar functionality.

Object.ExecuteGlobal(string)
ObjectVBS
Object with this method. You do not need to specify this object.
stringVariant
Specifies a string containing one or more instructions.

The following example executes an addition:

Dim MyResult, a, b
MyResult = 0
a = 5
b = 10
Call ExecuteGlobal("MyResult = a + b")
Call MsgBox(MyResult)

The following example defines a HelloWorld procedure and executes it. As the HelloWorld procedure is executed in the global namespace, you also can call this procedure outside the MySub procedure:

Sub MySub
  Dim MyStr
  MyStr = "Sub HelloWorld() : Call MsgBox(""Hello World!"") : End Sub"
  Call ExecuteGlobal(MyStr)
End Sub

Call MySub
Call HelloWorld

The following example reads in a VBS file and executes the scripts it contains. Then you can access the procedures in the VBS file:

Dim fso, MyVbsFile, MyFunctionsStr
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyVbsFile = fso.OpenTextFile("MyFunctions.vbs", 1, False)
MyFunctionsStr = MyVbsFile.ReadAll
Call MyVbsFile.Close
Set MyVbsFile = Nothing
Set fso = Nothing
Call ExecuteGlobal(MyFunctionsStr)

See Also

Objects Overview