Data Model > Accessing the UNICOM Intelligence Data Model > Working with the Metadata Model > MDM custom properties > Working with card and column definitions > Setting card, column, and punch values directly
 
Setting card, column, and punch values directly
This topic shows you how to set card, column, and punch definitions by setting the custom properties on the various objects directly. However, in practice you will normally find it easier to use the Metadata Model to Quantum component to set up the majority of the card, column, and punch definitions for an MDM Document. Setting up card and column definitions using the Metadata Model to Quantum component provides examples of doing this.
This mrScriptBasic example script does the following:
Creates a new Document object and opens the museum_qq.mdd sample file.
Sets the current user context to CardCol. All of the card and column custom properties are written to the CardCol user context. However, because we set the current user context to CardCol, it means we do not need to specify the user context each time we write a custom property.
Tests whether there is a DataSource object for the Quantum DSC. If there is, it is set as the current DataSource, and if not, a new DataSource is created and set as the current DataSource. We have to do this before we can access the DataSourceProperties collections.
Defines the Document-level card and column settings using the Document.DataSourceProperties collection.
Dim MyDocument, MyDataSource, MyElements, i, Punch

' Create the MDM object and open the Museum .mdd file in read-write mode
Set MyDocument = CreateObject("MDM.Document")
MyDocument.Open("C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Data\Mdd\museum_qq.mdd", , _
MDMLib.openConstants.oREADWRITE)

' Check whether a Quantum DSC DataSource object already exists
On Error Resume Next
Set MyDataSource = MyDocument.DataSources.Find("mrpunchdsc")
If MyDataSource Is Null Then
' Create a Quantum DSC DataSource object if one doesn't already exist
Set MyDataSource = MyDocument.DataSources.AddNew("mrPunchDsc", "mrPunchDsc", "MyDatFile.dat")
End If
Set MyDocument.DataSources.Current = MyDataSource
Err.Clear()
On Error Goto 0

' Set the current user context to CARDCOL
MyDocument.Contexts.Current = "CARDCOL"

' Set the Document-level card column definitions
With MyDocument.DataSourceProperties
.Item["SerialFullName"] = "Respondent.Serial"
.Item["CardSize"] = 80
.Item["SerialColCount"] = 5
.Item["CardNum_ColStart"] = 6
.Item["CardNum_ColCount"] = 2
.Item["PunchMask"] = "&-0123456789"
End With
The next section of the script sets up the card and column definitions for the School categorical variable using VariableInstance.DataSourceProperties:
' Set the card column definitions for the School variable
With MyDocument.Variables["School"].DataSourceProperties
.Item["CardStart"] = 1
.Item["ColStart"] = 9
.Item["ColCount"] = 2
End With
The next section sets up the card and column definitions for the categories using Element.DataSourceProperties:
' Set the card column definitions for the elements in the School variable
Set MyElements = MyDocument.Fields["School"].Elements
Punch = 1

For i = 0 To MyElements.Count - 1
' Only select categories that are not Other-specify categories
If MyElements[i].Type = MDMLib.ElementTypeConstants.mtCategory _
And MyElements[i].flag <> MDMLib.CategoryFlagConstants.flOther Then

With MyElements[i].DataSourceProperties
.Item["ColOffSet"] = 0
.Item["Punch"] = Punch
End With
Punch = Punch + 1
End If
Next
The next section shows you how to include in the Quantum ASCII file the coded responses to the Other Specify category and to specify that the open-ended responses and the source file information are to go into the .dau file. It also shows how to display the card and column information for the coding variable for the Other Specify category in UNICOM Intelligence Interviewer - Paper.
' Specify that the School.Other variable should go in the .dau file
With MyDocument.Variables["School.Other"].DataSourceProperties
.Item["CardStart"] = -1
.Item["ColStart"] = -1
.Item["ColCount"] = 0
' Set the PrintCardColFrom custom property for Paper
.Item["PrintCardColFrom"] = "School.Other.Codes"
End With

' Set the card column definitions for the School.Other.Codes variable
With MyDocument.Variables["School.Other.Codes"].DataSourceProperties
.Item["CardStart"] = 1
.Item["ColStart"] = 11
.Item["ColCount"] = 2
End With

' Specify that the School.Other.SourceFile variable should go in the .dau file
With MyDocument.Variables["School.Other.SourceFile"].DataSourceProperties
.Item["CardStart"] = -1
.Item["ColStart"] = -1
.Item["ColCount"] = 0
End With
The final section of the script saves the Document:
' Save the MDM Document
MyDocument.Save("C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Output\museum_qq_cardcols.mdd")
MyDocument.Close()
Here is the Document loaded into UNICOM Intelligence Interviewer - Paper using the Traditional Look group:
Note A similar example mrScriptBasic script is installed with the DDL and is called SetCardColsManually.mrs. For more information, see Sample mrScriptBasic files.
See also
Card, column, and punch definitions
Creating an Quantum specification using a script
Setting up card and column definitions using the Metadata Model to Quantum component
Working with card and column definitions