Data Model > Accessing the UNICOM Intelligence Data Model > Working with the Metadata Model > Working with the Metadata Model: Tutorial > Traversing the Routing collection
 
Traversing the Routing collection
The paper routing is a collection of RoutingItem objects. Each RoutingItem is simply a pointer to a question in the Fields collection.
mrScriptBasic example
The following mrScriptBasic example iterates through the Routing collection and prints out the name of each RoutingItem.
Dim MyDocument, MyRoutingItem, i

Set MyDocument = CreateObject("MDM.Document")

MyDocument.Open("C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Data\Mdd\museum_qq.mdd", , _
MDMLib.openConstants.oREAD)

For i = 0 To MyDocument.Routing.Count("Paper") - 1
Set MyRoutingItem = MyDocument.Routing.Item[i]["paper"]
Debug.Log(MyRoutingItem.Name)
Next
V.net example
A similar example in VB.NET is:
Private Sub Traverse_Routing_Collection()
Dim MyDocument As MDMLib.Document
Dim MyRoutingItem As MDMLib.RoutingItem
Dim i As Integer

MyDocument = New MDMLib.Document

MyDocument.Open(" [INSTALL_FOLDER]\IBM\SPSS\DataCollection\7\DDL\Data\Mdd\museum_qq.mdd", , _
MDMLib.openConstants.oREAD)

For i = 0 To MyDocument.Routing.Count("Paper") - 1
MyRoutingItem = MyDocument.Routing.Item(i, "Paper")
Debug.Write(vbCrLf & MyRoutingItem.Name)
Next i
End Sub
The RoutingItem object can also have a GotoCollection to store Go To information. Here is a snippet from the Museum survey displayed in UNICOM Intelligence Interviewer - Paper, which shows Go To routing instructions (variable names are shown in red):
The following mrScriptBasic example iterates through the Document.RoutingItems collection, which is a flat list of RoutingItem objects. For simple questions (objects of type mtVariable) that have Go To instructions, this example displays the names of the categories and the target variables.
Dim MyDocument, MyRoutingItem, MyGoToItem, MyObject
Dim i,j

Set MyDocument = CreateObject("MDM.Document")

MyDocument.Open("C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Data\Mdd\museum_qq.mdd", , _
MDMLib.openConstants.oREAD)

For i = 0 To MyDocument.RoutingItems.Count - 1
Set MyRoutingItem = MyDocument.RoutingItems.Item[i]
Debug.Log(MyRoutingItem.Name)

Set MyObject = MyRoutingItem.Item

If MyObject.ObjectTypeValue = MDMLib.ObjectTypesConstants.mtVariable Then
For j = 0 To MyRoutingItem.GotoCollection.Count - 1
Set MyGoToItem = MyRoutingItem.GotoCollection[j]
Debug.Log(" Response " + _
MyRoutingItem.GotoCollection.Name[j] + _
" - Go to " + MyGoToItem.Name)
Next
End If
Next
A similar example in VB.NET is:
Private Sub Traverse_Routing_and_Goto_Collections()
Dim MyDocument As MDMLib.Document
Dim MyRoutingItem As MDMLib.RoutingItem
Dim MyGoToItem As MDMLib.RoutingItem
Dim MyObject As Object
Dim i, j As Integer

MyDocument = New MDMLib.Document

MyDocument.Open(" [INSTALL_FOLDER]\IBM\SPSS\DataCollection\7\DDL\Data\Mdd\museum_qq.mdd", , _
MDMLib.openConstants.oREAD)

For i = 0 To MyDocument.RoutingItems.Count - 1
MyRoutingItem = MyDocument.RoutingItems.Item(i)
Debug.Write(vbCrLf & MyRoutingItem.Name)

MyObject = MyRoutingItem.Item

If MyObject.ObjectTypeValue = MDMLib.ObjectTypesConstants.mtVariable Then
For j = 0 To MyRoutingItem.GotoCollection.Count - 1
MyGoToItem = MyRoutingItem.GotoCollection(j)
Debug.Write(vbCrLf & " Response " & _
MyRoutingItem.GotoCollection.Name(j) & _
" - Go to " & MyGoToItem.Name)
Next j
End If
Next i
End Sub
Output
Here is the output for the part of the Museum survey shown above.
before
Response NO - Go to similar
Response NO_ANSWER - Go to similar
Response YES - Go to visits
visits
visit12
similar
Response NO - Go to others
Response NO_ANSWER - Go to others
Response YES - Go to locatio
Requirements
See Requirements.
Optional: Microsoft Visual Basic .NET 2003.
Next
Changing the question order
See also
Working with the Metadata Model: Tutorial