Data Model > Accessing the UNICOM Intelligence Data Model > Working with the Metadata Model > Working with metadata versions > Adding versions to the Short Drinks Example .mdd
 
Adding versions to the Short Drinks Example .mdd
The UNICOM Intelligence Developer Documentation Library comes with the Short Drinks sample .mdd, which contains 6 versions. For information about the versions, see The Short Drinks sample.
The mrScriptBasic example in this topic sets up some additional versions in the Short Drinks example .mdd file.
Version
Description
7
Original
8
Spend question added
8:1
Spend question text amended
9
Open-ended question about occupation deleted
10
Shared list and 2 tea questions added
10:1
New tea questions added to routing
10:2
Arabic language added
11
NA category removed from HH question
12
New category added and label of an existing category changed in HH question
Some of the version names combine the major version and minor version numbers in the form Major#:Minor#, where Major# is the number of the major version and Minor# is the number of the minor version. The version name is created automatically when the version is locked.
Minor version names are created when the version is locked after changes that involve the metadata and not the structure of the case data. In this example, those changes were a question label being changed (8:1), questions that already existed being added to the routing (10:1), and a language being added (10:2). When a version name contains a major version number only, it indicates that the changes in that version affected the structure of the case data: for example the addition or deletion of questions and/or categories.
Example
Here is an mrScriptBasic example that sets up the versions in the Short Drinks example .mdd file:
Dim MyDocument, MyVariable, MyVersion, MyRoutingItem
Dim MyElements, MyElement, MyOthervar, fso
Const TARGETDOC = "C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Output\short_drinks_with_extra_versions.mdd"

' Work on a copy of the short drinks sample .mdd file so that
' we do not add versions to the original file
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile("C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Data\Mdd\short_drinks.mdd", _
TARGETDOC, True)

' Create the MDM object and open the latest version of the
' Short Drinks .mdd copy in read-write mode
Set MyDocument = CreateObject("MDM.Document")
MyDocument.Open(TARGETDOC, , MDMLib.openConstants.oREADWRITE)

' Add version 7
MyDocument.Versions.AddNew()
MyDocument.Versions[MyDocument.Versions.Count - 1].Lock()
MyDocument.Versions[MyDocument.Versions.Count - 1].Description = "Original"

' Add version 8
MyDocument.Versions.AddNew()

Set MyVariable = MyDocument.CreateVariable("Spend")
MyVariable.DataType = mr.Long
MyVariable.Labels["Label"].Text["Question"]["ENU"] = _
"How much do you spend on our products?"
MyDocument.Fields.Add(MyVariable)

Set MyRoutingItem = CreateObject("MDM.RoutingItem")
Set MyRoutingItem.Item = MyDocument.Fields["Spend"]
MyDocument.Routing.Add(MyRoutingItem, "Paper", 11)

MyDocument.Versions[MyDocument.Versions.Count - 1].Lock()
MyDocument.Versions[MyDocument.Versions.Count - 1].Description = "Spend question added"

' Add version 8:1
MyDocument.Versions.AddNew()
MyDocument.Fields["Spend"].Labels["Label"] = _
"How much do you spend on our products each week?"

MyDocument.Versions[MyDocument.Versions.Count - 1].Lock()
MyDocument.Versions[MyDocument.Versions.Count - 1].Description = "Spend question label amended"

' Add version 9
MyDocument.Versions.AddNew()
MyDocument.Fields.Remove("occup")
MyDocument.Versions[MyDocument.Versions.Count - 1].Lock()
MyDocument.Versions[MyDocument.Versions.Count - 1].Description = "Variable deleted"

' Add version 10
MyDocument.Versions.AddNew()

Set MyElements = MyDocument.CreateElements("Teas")
Set MyElement = MyDocument.CreateElement("green", "Green")
MyElement.Type = MDMLib.ElementTypeConstants.mtCategory
MyElements.Add(MyElement)
Set MyElement = MyDocument.CreateElement("chinese", "Chinese")
MyElement.Type = MDMLib.ElementTypeConstants.mtCategory
MyElements.Add(MyElement)
Set MyElement = MyDocument.CreateElement("black", "Black")
MyElement.Type = MDMLib.ElementTypeConstants.mtCategory
MyElements.Add(MyElement)
Set MyElement = MyDocument.CreateElement("herbal", "Herbal")
MyElement.Type = MDMLib.ElementTypeConstants.mtCategory
MyElements.Add(MyElement)
Set MyElement = MyDocument.CreateElement("flavored", "Flavored")
MyElement.Type = MDMLib.ElementTypeConstants.mtCategory
MyElements.Add(MyElement)
Set MyElement = MyDocument.CreateElement("other", "Other, please specify")
MyElement.Type = MDMLib.ElementTypeConstants.mtCategory

Set MyOthervar = MyDocument.CreateVariable("other", "Other specify")
MyOthervar.DataType = mr.Text
Set MyElement.OtherVariable = MyOthervar
MyElements.Add(MyElement)

Set MyElement = MyDocument.CreateElement("na", "Not answered")
MyElement.Type = MDMLib.ElementTypeConstants.mtCategory
MyElement.Flag = MDMLib.CategoryFlagConstants.flNoanswer
MyElements.Add(MyElement)

MyDocument.Types.Add(MyElements)

Set MyVariable = MyDocument.CreateVariable("Which_Teas", _
"Which of these teas do you drink? (Select all that apply)")
MyVariable.DataType = mr.Categorical
MyVariable.MinValue = 1
MyVariable.MaxValue = 5
Set MyVariable.Elements.Reference = MyElements
MyDocument.Fields.Add(MyVariable)

Set MyVariable = MyDocument.CreateVariable("Favorite", _
"Which is your favorite type of tea? (Select one answer only)")
MyVariable.DataType = mr.Categorical
MyVariable.MinValue = 1
MyVariable.MaxValue = 1
Set MyVariable.Elements.Reference = MyElements
MyDocument.Fields.Add(MyVariable)

MyDocument.Versions[MyDocument.Versions.Count - 1].Lock()
MyDocument.Versions[MyDocument.Versions.Count - 1].Description = "Shared list and 2 questions added"

' Add version 10:1
MyDocument.Versions.AddNew()

Set MyRoutingItem = CreateObject("MDM.RoutingItem")
Set MyRoutingItem.Item = MyDocument.Fields["Which_Teas"]
MyDocument.Routing.Add(MyRoutingItem, "Paper", 12)
Set MyRoutingItem = CreateObject("MDM.RoutingItem")
Set MyRoutingItem.Item = MyDocument.Fields["Favorite"]
MyDocument.Routing.Add(MyRoutingItem, "Paper", 13)

MyDocument.Versions[MyDocument.Versions.Count - 1].Lock()
MyDocument.Versions[MyDocument.Versions.Count - 1].Description = "New questions added added to routing"

' Add version 10:2
MyDocument.Versions.AddNew()
MyDocument.Languages.Add("ARA")
MyDocument.Versions[MyDocument.Versions.Count - 1].Lock()
MyDocument.Versions[MyDocument.Versions.Count - 1].Description = "Arabic language added"

' Add version 11
MyDocument.Versions.AddNew()
Set MyElements = MyDocument.Fields["HHSIZE"].Elements
MyElements.Remove("NA")
MyDocument.Versions[MyDocument.Versions.Count - 1].Lock()
MyDocument.Versions[MyDocument.Versions.Count - 1].Description = "HH NA category removed"

' Add version 12
MyDocument.Versions.AddNew()
Set MyElement = MyDocument.Fields["HHSIZE"].Elements.AddNewElement("HH_7", _
MDMLib.ElementTypeConstants.mtCategory)
MyElement.Label = "7 or more people"
Set MyElements = MyDocument.Fields["HHSIZE"].Elements
MyElements["HH_6"].Label = "6 people"
MyDocument.Versions[MyDocument.Versions.Count - 1].Lock()
MyDocument.Versions[MyDocument.Versions.Count - 1].Description = _
"HH category added and label changed"

' List all versions
For Each MyVersion In MyDocument.Versions
Debug.Log(MyVersion.Name + " : " + MyVersion.Description)
Next

MyDocument.Save()
MyDocument.Close()
The next topic, Working with multiple versions, shows how to extract a single version from the short_drinks.mdd file and save the extracted version in a new .mdd file.
Requirements
UNICOM Intelligence Data Model
See also
Working with metadata versions
Extracting a single version to a new .mdd file
Working with multiple versions