Displaying card, column, and punch values
This topic provides an example of reading the card, column, and punch definitions that we set up in
Setting card, column, and punch values directly. You can use similar code to display the card, column, and punch definitions that you set up using the Metadata Model to Quantum or the Metadata Model to Quantum component.
The main thing to remember when you are reading card, column, and punch definitions is that you need to set the current data source correctly because the definitions are stored in the DataSourceProperties collections for a specific data source. You also need to explicitly specify the user context or set the current user context to CARDCOL. In this example, we will set the current user context. Here is the mrScriptBasic code:
Dim MyDocument, MyDataSourceProperties, MyElement, i
' Create the MDM object and open the file we created in the
' topic "Setting Card, Column, and Punch Values Directly"
Set MyDocument = CreateObject("MDM.Document")
MyDocument.Open("C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Output\museum_qq_cardcols.mdd", , _
MDMLib.openConstants.oREADWRITE)
' Set the Quantum DSC data source as the current DataSource
Set MyDocument.DataSources.Current = _
MyDocument.DataSources.Find("mrpunchdsc")
' Set the current user context to CARDCOL
MyDocument.Contexts.Current = "CARDCOL"
' Display the Document-level card column defintions
Set MyDataSourceProperties = MyDocument.DataSourceProperties
Debug.Log("Definitions for Document:")
For i = 0 to MyDataSourceProperties.Count - 1
Debug.Log(MyDataSourceProperties.Name[i] + ": " _
+ CText(MyDataSourceProperties.Item[i]))
Next
' Display the VariableInstance object's card column definitions
Set MyDataSourceProperties = _
MyDocument.Variables["School"].DataSourceProperties
Debug.Log(mr.CrLf + "Definitions for School variable:")
For i = 0 to MyDataSourceProperties.Count - 1
Debug.Log(MyDataSourceProperties.Name[i] + ": " _
+ CText(MyDataSourceProperties.Item[i]))
Next
' Display the ElementInstance object's punch definitions.
' These are inherited from the Element object.
Debug.Log(mr.CrLf + "Definitions for categories of School variable:")
For Each MyElement In MyDocument.Variables["School"].ElementInstances
Debug.Log(MyElement.Name + " Punch: " _
+ CText(MyElement.DataSourceProperties.Item["Punch"]) _
+ " ColOffset: " _
+ CText(MyElement.DataSourceProperties.Item["ColOffset"]))
Next
MyDocument.Close()
Note that MDM Explorer does not display the inherited custom properties. This means that to see the punch definitions in MDM Explorer, you must look at the DataSourceProperties on the Element objects and not the ElementInstance objects. For more information, see
Viewing custom properties in MDM Explorer.
A similar example mrScriptBasic script is installed with the DDL and is called
ReadCardCols.mrs. For more information, see
Sample mrScriptBasic files.
See also