Scripting > mrScriptBasic overview > mrScriptBasic examples > 9: Running one mrScriptBasic script from another
 
9: Running one mrScriptBasic script from another
This example demonstrates how mrScriptBasic can be used to preprocess and execute a second mrScriptBasic script. You might want to use this technique to create a tool that manages the execution of other mrScriptBasic scripts.
In the example, the mrPrePro preprocessor is used to preprocess the script to be executed. For more information about mrPrePro, including a full list of its options, see mrPrePro preprocessor.
The mrScript interface is then used to parse and execute the preprocessed script.
' The name of the script to be preprocessed
' and executed...
#define Script "C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Scripts\General\mrScriptBasic\Functions.mrs"

Dim PrePro, Params, ProcessedScript, Message
Dim ScriptEngine, ScriptProgram

' Create script preprocessor and
' engine objects...
Set PrePro = CreateObject("mrPrePro.PrePro")
Set ScriptEngine = CreateObject("mrScript.ScriptEngine")

' Specify the options for the preprocessor...
Params = "-z --c99"

' This variable must be initialized
' as a string...
Message = ""

' Preprocess the script...
ProcessedScript = PrePro.Run("#include """ + Script + """", Params, Message)

' Check if preprocesing failed...
If Len(ProcessedScript) = 0 Then
Debug.Log("Preprocessing failed for script: " + Script)
Exit
End If

' Parse the script...
Set ScriptProgram = ScriptEngine.Parsers[0].Parse(ProcessedScript, ScriptEngine, 0)

' Execute the script...
ScriptEngine.Execute(ScriptProgram, 0)
Note In mrScriptBasic, you can not access the message produced by mrPrePro's Run method, although this is possible in VBScript or a program. See mrPrePro preprocessor for more information.
To pass a value to the script being executed, such as the name of an input file, programmatically add a #define preprocessor directive to the start of the script (see #define and #undef). The following example shows how to do this by modifying one of the lines in the above script:
ProcessedScript = PrePro.Run("#define MddName ""C:\MyQuestionnaire.mdd""" _ + mr.CrLf + "#include """ + Script + """", Params, Message)
See also
mrScriptBasic examples