Developer Documentation Library > Data Model > Accessing the UNICOM Intelligence Data Model > Working with the Metadata Model > Working with the Metadata Model: Tutorial > Creating a variable without referencing the MDM component
 
Creating a variable without referencing the MDM component
This example uses similar code to the one in Using Visual Basic to create and save a variable, but without a reference to the MDM component. The changes are:
The Visual Basic variables MyDocument and MyVariable are declared as data type Object.
The Visual Basic function CreateObject is used to create an instance of a new Document object.
When setting the value of MyVariable.DataType, it is possible to use the enumeration constant mtLong only if you add an Imports statement to the namespace declarations section of your code, as described in the previous topic. Otherwise you need to use the numeric value of the mtLong constant. You can find the values for the different data types using the Object Browser. When you select an enumeration constant on the right side of the Object Browser, the lower pane shows its numeric value.
Private Sub Create_Numeric_Variable()
Dim MyDocument As Object
Dim MyVariable As Object

' Instantiate a new MDM document
MyDocument = CreateObject("MDM.Document")

' Create a numeric variable "Spend" with a range of 1-1000
MyVariable = MyDocument.CreateVariable("Spend", _
"How much do you spend on our products per year?")
MyVariable.DataType = 1 ' mtLong
MyVariable.MinValue = 0
MyVariable.MaxValue = 1000
MyDocument.Fields.Add(MyVariable)

' Save the Document
MyDocument.Save(" [INSTALL_FOLDER]\IBM\SPSS\DataCollection\7\DDL\Output\My Numeric Variable2.mdd")
' Release the Document
MyDocument.Close()
When you create a variable this way, you lose the advantage of IntelliSense in the Visual Studio Editor.
Requirements
See Requirements.
Next topic
Loading and reading a variable
See also
Working with the Metadata Model: Tutorial