Developer Documentation Library > Data Model > Accessing the UNICOM Intelligence Data Model > Working with the Metadata Model > MDM custom properties > Working with card and column definitions > Using standard Quantum settings
 
Using standard Quantum settings
This is a mrScriptBasic example that shows using the Metadata Model to Quantum component to set up the card, column, and punch custom properties. This example is suitable for setting up card, column, and punch definitions in a new .mdd file and does the following:
Uses the "{..}" version expression to open all versions of the Short Drinks sample .mdd file. For more information, see Working with multiple versions.
Checks whether the MDM Document contains a DataSource object for the Quantum DSC. If it does, the example sets it as the current DataSource, and if not creates a new DataSource object and sets it as the current DataSource. Using the Metadata Model to Quantum component requires having a Quantum DSC DataSource.
Sets the Metadata Model to Quantum object's properties so that the definitions will use the standard Quantum options of using multiple cards of 80 columns and storing the serial number in columns 1-5 and the card number in columns 6-7. If you do not set these properties, a single card of infinite length is used.
Calls the Metadata Model to Quantum object's AllocateCardColumnPunch method to automatically allocate card, column, and punch definitions to all of the variables in the .mdd file.
See also MDM2Quantum.AllocateCardColPunch in the MDM Object Model Reference.
Calls the Metadata Model to Quantum object's WriteToCommaSeparatedFile method to write the allocations to a comma separated variable file. This contains a record of the definitions used. Notice that the Now function is used to create a unique filename based on the current date and time. This means that if you run the script again, this file will not be overwritten.
Dim MyDocument, M2Q, MyDataSource

' Create the MDM object and open all versions of the Short
' Drinks .mdd file in read-write mode
Set MyDocument = CreateObject("MDM.Document")
MyDocument.Open("C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Data\Mdd\short_drinks.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

' Create the MDM2Quantum object
Set M2Q = CreateObject("MDM2QuantumLib.MDM2Quantum")

' Set the MDM Document into the MDM2Quantum object
Set M2Q.MDMDocument = MyDocument

' Set the MDM2Quantum properties to use the standard Quantum
' setting of multiple cards with 80 columns. Delete these lines
' if you want to use one card of unlimited length
M2Q.SerialFullName = "Respondent.Serial"
M2Q.SerialColCount = 5
M2Q.CardNumColCount = 2
M2Q.CardNumColStart = 6
M2Q.CardSize = 80

' Run the allocation
M2Q.AllocateCardColPunch(True)

' Write the data map to a .csv file using the
' Now function to create a unique filename
M2Q.WriteToCommaSeparatedFile("C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Output\short_drinks1." _
+ CText(CDouble(Now())) + ".csv")

' Save the Short Drinks .mdd file to a new file
MyDocument.Save("C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Output\short_drinks1.mdd")
MyDocument.Close()
The next example shows how to clear old card, column, and punch definitions in an .mdd file and reallocate: see Clearing old definitions and reallocating.
See also
Working with card and column definitions