Platforms to show: All Mac Windows Linux Cross-Platform

Back to WindowsScriptMBS class.

WindowsScriptMBS.AddCode(code as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Windows MBS Win Plugin 10.0 ❌ No ✅ Yes ❌ No ❌ No Desktop, Console & Web
Add code to the global module.
Example
dim w as new WindowsScriptMBS

w.Language = "VBScript"

w.AddCode "a = 1" // define some global variables
w.AddCode "b = 2"

If you use VBScript, you don't need "dim" keyword for defining variables.

Some examples using this method:

WindowsScriptMBS.ClearError

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Windows MBS Win Plugin 10.0 ❌ No ✅ Yes ❌ No ❌ No Desktop, Console & Web
Clears the current error.

WindowsScriptMBS.Eval(code as string) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Windows MBS Win Plugin 10.0 ❌ No ✅ Yes ❌ No ❌ No Desktop, Console & Web
Evaluate an expression within the context of the global module.

WindowsScriptMBS.ExecuteStatement(statement as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Windows MBS Win Plugin 10.0 ❌ No ✅ Yes ❌ No ❌ No Desktop, Console & Web
Execute a statement within the context of the global module.
Example
dim w as new WindowsScriptMBS

w.Language = "VBScript"

w.AddCode "a = 1"
w.AddCode "b = 2"

w.AllowUI = true
w.ExecuteStatement "msgbox a+b" // shows 3

w.AllowUI = false
w.ExecuteStatement "msgbox a+b" // shows exception with access denied

Exception e as WindowsScriptErrorExceptionMBS
MsgBox e.message

Some examples using this method:

WindowsScriptMBS.Reset

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Windows MBS Win Plugin 10.0 ❌ No ✅ Yes ❌ No ❌ No Desktop, Console & Web
Reset the scripting engine to a newly created state.

WindowsScriptMBS.Run(functionName as string, parameters() as string) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Windows MBS Win Plugin 10.0 ❌ No ✅ Yes ❌ No ❌ No Desktop, Console & Web
Call a procedure defined in the global module.
Example
dim w as new WindowsScriptMBS

// First try VBScript
w.Language = "VBScript"

dim lines(-1) as string

lines.append "Function Test(a,b)"
lines.append "Test = a+b"
lines.append "End Function"

w.AddCode Join(lines, EndOfLine.Windows)

dim p(-1) as string = array("Hello ", "World from VBScript")
dim x as string = w.Run("Test", p)

'MsgBox x

// Second try JScript
w.Language = "JScript"

redim lines(-1)
lines.append "function Test(a,b)"
lines.Append "{"
lines.append "return a+b;"
lines.append "}"

w.AddCode Join(lines, EndOfLine.Windows)

p = array("Hello ", "World from JavaScript")
x = w.Run("Test", p)

MsgBox x

Exception e as WindowsScriptErrorExceptionMBS
MsgBox "Exception: "+e.message

The items on this page are in the following plugins: MBS Win Plugin.


The biggest plugin in space...