Table scripting syntax quick reference
UNICOM Intelligence Reporter uses the mrScriptBasic syntax. This topic shows examples of some of the scripting syntax that you might find in the sample table scripts.
'! ... !'
'! and !' surrounding multiple lines of text indicate comment text that is ignored when the script is run.
'! *********************************************
This sample creates a number of tables that
illustrate how the Base element is calculated.
********************************************* !'
'
' Create tables
The ' character at the start of a line indicates a single-line comment.
_
"meanvisits 'Average number of visits' mean(visits) }", _ "Modified Signs variable with mean of Visits")
A space followed by underscore ( _) at the end of a line signifies that the syntax continues on the next line.
You cannot split a line in the middle of a parameter by using the underscore character. This example splits a line in the middle of a parameter by closing the parameter, splitting the line, and then reopening the parameter, using the syntax " + _. The " character closes the parameter, the + adds the two halves of the syntax together again, and the _ is the line continuation character. The next line begins with ", to reopen the parameter.
.AddNew("Table2", "salary{base() [IsHidden=True]," + _
"Mn 'Lowest' min(salary), Mx 'Highest' max(salary)," + _
"Av 'Average' mean(salary) [Decimals=0]} * gender",
"Salary level by gender of employee")
"! ... !"
TableDoc.Tables.AddNew("Table1", "!
age {
E1116_years,
E1720_years,
E2124_years,
E2534_years,
E3544_years
}
*
gender!"
)
"! and !" enclosing a string (instead of " and ") enable you to split the string over several lines for display purposes.
+
TableDoc.Tables.AddNew("Table1", "age * interview + gender")
Where the
+ symbol is used in a table specification, it indicates that two variables are concatenated together on an axis. For more information, see
Concatenation and nesting.
>
TableDoc.Tables.AddNew("Table2", "age * interview > gender")
Where the
> symbol is used in a table specification, it indicates that variables are nested. For more information, see
Concatenation and nesting.
The > symbol is also used in a different context as the “greater than” operator.
For more information, see
Comparison operators.
[...]
age{.., E65_years [IncludeInBase=False]}
Square brackets surround the definition of an element's properties.
If more than one property is defined for the same element, both are enclosed in a single set of square brackets, separated by a comma.
age{.., E65_years [IsHidden=True, IncludeInBase=False]}
For more information, see
Element properties.
{...}
TableDoc.Tables.AddNew("Table1", "interest{Whales, Fossils, Dinosaurs} * gender")
Braces surround the lists of categories and other elements that form a variable’s axis expression.
For more information, see
Element list syntax.
"..."
TableDoc.Default.Annotations[7].Specification = "<IMG SRC=""[INSTALL_FOLDER]\IBM\SPSS\DataCollection\7\DDL\ Output\logo.gif""/>"
In cases where you want to nest syntax containing quote marks inside other syntax that also contains quote marks, you must “escape” the quote marks in the inner section of the script so that they are not interpreted as forming the end of the outer section. You do this by using two sets of quote marks instead of one.
^
.AddNew("Table7", "Region{.., ^No_answer} * NumRooms > Person.Gender", "Filtered table")
The ^ character represents the NOT operator; in this example, it excludes the No_answer category from the variable.
^.
.Table7.Filters.AddNew("MalesAndMotorBikesAtPerson", _
"Gender = {Male} And ^.Sum(Vehicle.(VehicleType = {Motorbike})) > 0", , "person")
The characters ^. represent the down-lev symbol.
For more information, see
Hierarchical expressions.
.(
The characters .( represent the up-lev symbol.
Select Case
Select Case Field.ObjectTypeValue
Case 0 ' mtVariable - Simple variable
If Field.DataType = mr.Long Or Field.DataType = mr.Double Then
' It's a numeric - autosummarize
AutoSummarizeNumeric(Field)
TableDoc.Tables.AddNew("Table" + CText(TableDoc.Tables.Count + 1), _
Field.FullName, Field.Label)
End If
Case 1, 2, 3, 18 ' Array, Grid, Class, or Compound
' It's a container, process the contents
MakeTablesFromNumerics(TableDoc, Field.Fields)
End Select
Case statements conditionally execute a group of statements, depending on the value of an expression.
For more information, see
Select Case.
Const
Const MDD_FILE = "[INSTALL_FOLDER]\IBM\SPSS\DataCollection\7\DDL\ Data\Xml\Museum.mdd"
The Const keyword introduces a user-defined constant that you can use to replace parameters that you want to reuse or change. The constant replaces the parameter elsewhere in the script, for example:
TableDoc.DataSet.Load(MDD_FILE, , XML_FILE, "mrXmlDsc")
For more information, see
User-defined constants.
Dim
Dim TableDoc
The Dim keyword introduces the syntax that declares one or more variables for use in your script.
For more information, see
Variables.
Do...Loop
Do Until AdoRS.EOF
For Each Field In AdoRS.Fields
Set XmlAnswerElement =
XmlTextElement.appendChild(XmlDoc.CreateElement("answer"))
Set CDATASection = XmlDoc.createCDATASection(Field)
XmlAnswerElement.appendChild(CDATASection)
Next
AdoRS.MoveNext()
Loop
The Do Until Loop repeats a block of statements while a condition is True or until a condition becomes True.
For more information, see
Do...Loop.
For...Next
For Each Field In AdoRS.Fields
Set XmlAnswerElement =
XmlTextElement.appendChild(XmlDoc.CreateElement("answer"))
Set CDATASection = XmlDoc.createCDATASection(Field)
XmlAnswerElement.appendChild(CDATASection)
Next
For... Next repeats a group of statements a specified number of times. For more information, see
For...Next.
For Each... Next repeats a group of statements for each element in a collection. For more information, see
For Each...Next.
If...Then...Else
If Field.AxisExpression.IsEmpty() Then
' It hasn't already got an axis expression, so create one
Field.AxisExpression = "{min 'Minimum' min(" + Field.FullName + _
"), max 'Maximum' max(" + Field.FullName + _
"), mean 'Mean' mean(" + Field.FullName + _
"), StdDev 'Standard deviation' StdDev(" + Field.FullName + _
"), StdErr 'Standard error' StdErr(" + Field.FullName + ")}"
End If
If...Then...Else conditionally executes a group of statements, depending on the value of an expression.
For more information, see
If...Then...Else.
On Error
On Error Resume Next
On Error is used to enable and disable error handling.
For more information, see
On Error and
Resume Next.
Set
Set TableDoc = CreateObject("TOM.Document")
The Set keyword introduces an assignment statement, which evaluates an expression and assigns the results to a variable.
For more information, see
Assignment statements.
With
With TableDoc.Tables
.AddNew("Signs", "signs", "Unmodified Signs variable")
.AddNew("SignsNew", "signs{Yes, No}", "Two elements of the Signs variable")
End With
The With and End With keywords surround a block of statements that all apply to the same object (in this example, adding two new tables to the Tables object). This is a compact way of carrying out a number of actions on a single object.
For more information, see
With.
Dynamic property expansion
Set MyElement = MyTable.Top.Gender.Elements.Male
Examples such as this use dynamic property expansion to provide a shorter way of writing a complex line of script. The equivalent script without dynamic property expansion would look like this:
Set MyElement = _
MyTable.Axes.Item["Top"].SubAxes.Item["gender"].Elements.Item["Male"]
For more information, see
Dynamic property expansion.
Additional reference information
When you create variables and elements, you must follow the mrScriptBasic naming conventions. See
Naming conventions.
A number of keywords in scripts are reserved words; you can use reserved words in scripts. See
mrScriptBasic keyword summary.
See also
Learning mrScriptBasic in the UNICOM Intelligence Developer Documentation Library.
For more information about the features that help you write and run mrScriptBasic scripts, see
Creating your first mrScriptBasic script.
See also