Data Model > Accessing the UNICOM Intelligence Data Model > Working with the Metadata Model > Working with the Metadata Model: Tutorial > Sorting Element and VariableInstance objects
 
Sorting Element and VariableInstance objects
The Element, Elements, and VariableInstance objects have a hidden default property that returns the full name. This allows you to sort these objects alphabetically on their full name using the SortAsc and SortDesc functions.
mrScriptBasic example
This mrScriptBasic code sorts the elements in the plan_view variable in the Museum sample:
Dim MyDocument, MyElement

Set MyDocument = CreateObject("MDM.Document")
MyDocument.Open("C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Data\Data Collection File\museum.mdd", , _
MDMLib.openConstants.oREAD)

Debug.Log("Elements in default order: ")

For Each myElement in MyDocument.Fields["plan_view"].Elements
Debug.Log(myElement)
Next

Debug.Log(mr.CrLf + "Elements in ascending order: ")

For Each myElement in SortAsc(MyDocument.Fields["plan_view"].Elements)
Debug.Log(myElement)
Next

Debug.Log(mr.CrLf + "Elements in descending order: ")

For Each myElement in SortDesc(MyDocument.Fields["plan_view"].Elements)
Debug.Log(myElement)
Next
Output
Elements in normal order:
Dinosaurs
Conservation
Fish_and_reptiles
Fossils
Birds
Insects
Whales
Mammals
Minerals
Ecology
Botany
Origin_of_species
Human_biology
Evolution
Wildlife_in_danger
Elements in ascending order:
Birds
Botany
Conservation
Dinosaurs
Ecology
Evolution
Fish_and_reptiles
Fossils
Human_biology
Insects
Mammals
Minerals
Origin_of_species
Whales
Wildlife_in_danger
Elements in descending order:
Wildlife_in_danger
Whales
Origin_of_species
Minerals
Mammals
Insects
Human_biology
Fossils
Fish_and_reptiles
Evolution
Ecology
Dinosaurs
Conservation
Botany
Birds
Next
Name handling and object look up
See also
Working with the Metadata Model: Tutorial
SortAsc
SortDesc