Scripting > mrScriptBasic overview > How does mrScriptBasic compare to VBScript?
 
How does mrScriptBasic compare to VBScript?
mrScriptBasic overview provides an overview of the features that are supported by mrScriptBasic but not by Visual Basic and VBScript. This topic summarizes some of the main differences in syntax between mrScriptBasic and VBScript.
See also How does mrScriptBasic compare to Visual Basic?
Option explicit
In mrScriptBasic, by default you need to explicitly declare variables using the Dim statement. If you want variables to be declared implicitly, you need to add the Option Implicit statement at the beginning of your script. However, this is not recommended. In contrast, in VBScript, Option Implicit is the default. See Variables for more information.
Variable scope
When working in VBScript, a variable defined in the mrScriptBasic script is visible to Functions and Sub procedures. By default, this is not true in mrScriptBasic. To make mrScriptBasic behave in the same way as VBScript, you must include an Option GlobalVariables statement in your script. See Variables for more information.
Array variables
In mrScriptBasic you specify array variables using [] (brackets) instead of () (parentheses) as you would in VBScript. This table provides some examples of specifying array variables in mrScriptBasic and VBScript. See Variables for more information.
Array
mrScriptBasic
VBScript
One dimension with 10 elements
Dim myArray[10]
Dim myArray(10)
Two dimensions with 5 and 10 elements respectively
Dim myArray[5][10]
Dim myArray(5, 10)
Dynamic array
Dim myArray[]
Dim myArray()
Array Sub declaration
Sub MySub(myArray[])
Sub MySub(myArray)
Unless Dim is used to define a variable as an array, an array value is treated as a categorical value. The elements of a categorical value are read only. For example, the following is valid because the array variable is defined as an array:
Dim MyArray[2]
MyArray[0] = "Hello"
MyArray[1] = " World"
However, the following is not valid because the value is a categorical:
Dim MyCategorical
MyCategorical = {1,2,3}
Debug.MsgBox(MyCategorical[0]) ' displays 1
MyCategorical[0] = 2 ' error - it is not possible to assign an element of a categorical
Removing an object reference from a variable
In mrScriptBasic, use Null instead of Nothing to remove an object reference. For example:
Set MyObject = Null
In mrScriptBasic, use the IsNullObject function in the UNICOM Intelligence Function Library to test if an object reference no longer exists. For example:
If MyObject.IsNullObject() Then
' No object reference exists
...
End If
Default property expansion
mrScriptBasic uses [] (brackets) instead of () (parentheses) to reference an object in a collection using the collection's default property (which is typically Item). This means that object lookup is consistent with the syntax used for MDM full names.
For example, to reference the age question in an MDM Document.Fields collection, using the default property, you could use code similar to the following in mrScriptBasic:
LabelText = MyDocument.Fields["age"].Label
Whereas in VBScript, you would need to use code similar to the following:
LabelText = MyDocument.Fields("age").Label
In mrScriptBasic you can refer to objects in this manner even when Item is a method rather than a property, provided it is the default member for the collection. However, generally you call methods using parentheses and not brackets. See Call statements for more information.
Parameters for object properties
Specify parameters for object properties in mrScriptBasic using [] (brackets) instead of () (parentheses) as in VBScript. To specify more than one parameter in mrScriptBasic, enclose each parameter in brackets instead of separating them with a comma as in VBScript. For example, the Text property of the MDM Label object has two parameters, user context and language. You would specify the parameters in mrScriptBasic as follows:
myText = myObject.Labels["Label"].Text["Question"]["ENU"]
The equivalent line in VBScript would be:
myText = myObject.Labels("Label").Text("Question", "ENU")
Call statements
mrScriptBasic always requires a call statement to be followed by () (parentheses), regardless of whether the method or function returns a value. In VBScript, parentheses are not required when calling a subroutine that does not return a value. For example, the following mrScriptBasic code calls the MDM Document.Save method:
MdmDoc.Save ("C:\Samples\myDocument.mdd")
The equivalent VBScript code would be:
MdmDoc.Save "C:\Samples\myDocument.mdd"
In VBScript, you can optionally prefix a call statement with the Call keyword. However, the use of the Call keyword is not valid syntax in mrScriptBasic.
Default method expansion
Unlike VBScript, mrScriptBasic does not expand calls to an object's default method. For example, the default member of the ClearCase.ClearTool object is the CmdExec method. In VBScript, you can use the following syntax to call the method:
Set Cleartool = CreateObject("ClearCase.ClearTool")
sDiff = ClearTool(sCmd)
However, in mrScriptBasic you need to include the method name as follows:
Set Cleartool = CreateObject("ClearCase.ClearTool")
sDiff = ClearTool.CmdExec(sCmd)
Functions
mrScriptBasic uses the functions in the UNICOM Intelligence Function Library, which has been specially designed for use by the market research industry. This means that some of the functions that are built into VBScript and Visual Basic are not available in mrScriptBasic. See Visual Basic function equivalents for more information.
Bitwise operations
In mrScriptBasic, you cannot use the And, Not, Or, and Xor operators for bitwise operations as you can in VBScript. However, you can use the bitwise functions in the UNICOM Intelligence Function Library. See Bitwise operations for more information.
Integer arithmetic
When the following code is executed in VBScript, x has a value of 2.4:
x = 12/5
When the same code is executed in mrScriptBasic, x has a value of 2. This is because 12 and 5 are both integers (type Long) and when you perform an arithmetic operation on two integers, the result is also an integer. If you want the result to be a real number (type Double), you need to convert the values to real numbers, for example:
x = 12.0/5.0
The result is then 2.4. See Arithmetic operators for more information.
Concatenation operator
In mrScriptBasic you cannot use an ampersand (&) to concatenate two strings together as you can in VBScript. In mrScriptBasic you use the addition (+) operator instead. For example, the following line would give a syntax error in mrScriptBasic:
ErrorText = "Error : " & Err.Description
Instead you need to concatenate the two strings using the + operator:
ErrorText = "Error : " + Err.Description
When concatenating values using the addition operator (+) all of the values must be Text values. Use the CText function to convert other types of values to Text:
ErrorText = "Error : " + Err.Description + ", Line : " + CText(Err.LineNumber)
Alternatively, use the MakeString function to ensure all of the values are converted to Text:
ErrorText = MakeString("Error : ", Err.Description, ", Line : ", Err.LineNumber)
Error handling sections
Unlike VBScript, mrScriptBasic supports the use of an On Error Goto <location> statement, which you can use to add an error-handling section to your script. For example:
On Error Goto Handler

' Main section of script where error may occur
...

Exit

Handler:
Debug.Log("Error on line " + CText(Err.LineNumber) + " : " + Err.Description)
Make sure that you always include an Exit statement immediately before your error-handling section. See On Error for more information.
Automatic calling of Err.Clear
Like VBScript, mrScriptBasic calls the Err.Clear method automatically whenever an On Error Resume Next statement is executed. However, unlike VBScript, mrScriptBasic does not call the Err.Clear method automatically when an Exit Sub or Exit Function statement is executed.
While statements
In mrScriptBasic, the end of a While statement is defined by End While instead of VBScript's Wend keyword. See While...End While for more information.
Combining statements on one line
Unlike VBScript, in mrScriptBasic it is not possible to combine multiple statements on a single line. Similarly, you cannot combine a GoTo label and a statement on one line. Combining statements on a single line is not supported because it can cause problems for GUI tools that use mrScriptBasic.
See also
mrScriptBasic overview