Desktop User Guides > Professional > Table scripting > Working with metadata > Working with labels > A complete example
 
A complete example
This example does the following:
Creates top line tables for all of the simple categorical variables in the UNICOM Intelligence Interviewer - Paper routing. This means that the tables are created in the same order as they appear on the questionnaire.
Sets the user context to Question in both the table document and the MDM document.
Changes the text on the autobase element to read "Total" instead of "Base".
Sets up the table description to show the variable short name (which stores the question number) as well as the question text.
Uses the UseVariableLabels export property to export the variable names rather than the variable labels.
' Set the user context in the table document to Question
TableDoc.Context = "Question"

' Set the current user context in the MDM Document to Question
TableDoc.DataSet.MDMDocument.Contexts.Current = "Question"

' Set the Analysis context as an alternative for Question.
' This means that if texts are missing in the Question context,
' they will automatically be taken from the Analysis context.
TableDoc.DataSet.MDMDocument.Contexts.Item["Question"].Alternatives.Add("Analysis")

Dim MyCounter, i, MyRoutingItem, MyField, MyTableName, MyTableSpec, MyTableDescription

' Set the counter to zero
MyCounter = 0

' Loop through the Paper routing items
' and create a top-line table for all of
' the simple categorical variable instances in the routing
' that have a short name defined

For i = 0 To TableDoc.DataSet.MDMDocument.RoutingItems.Count - 1
Set MyRoutingItem = TableDoc.DataSet.MDMDocument.RoutingItems.Item[i]
Set MyField = TableDoc.DataSet.MDMDocument.Fields[MyRoutingItem.Name]
' Test that it is a simple variable and that the short name label isn't blank
If MyField.ObjectTypeValue = 0 _
And Not MyField.Labels["ShortName"].Text["Question"].IsEmpty() Then
' Check that it's a categorical variable
If MyField.DataType = mr.Categorical Then
MyCounter = MyCounter + 1
MyTableName = "Table" + CText(MyCounter)
MyTableSpec = MyField.FullName
MyTableDescription = MyField.Labels["ShortName"].Text
MyTableDescription = MyTableDescription + ": " + _
MyField.Labels["Label"].Text
TableDoc.Tables.AddNew(MyTableName, MyTableSpec, MyTableDescription)
' Set the label on the Autobase element to read "Total" instead of "Base"
TableDoc.Tables[MyTableName].Side.SubAxes[MyTableSpec].Elements.Base.Label = "Total"
End If
End If
Next

' Populate the tables
TableDoc.Populate()

' Export the tables
With TableDoc.Exports.mrHtmlExport
.Properties["Interactive"] = True
.Properties["LaunchApplication"] = True
.Properties["DisplayOption"] = "Table Only"

' Export variable names rather than labels
.Properties["UseVariableLabels"] = False

.Properties["LayoutStyle"] = "Frame Table of Contents"
.Export(" [INSTALL_FOLDER]\IBM\SPSS\DataCollection\7\DDL\Output\WorkingWithLabels.htm")
End With
HTML file output by WorkingWithLabels.mrs script, showing table of contents with table 14 selected
This graphic is described in the surrounding text.
See also
Working with labels