Survey Tabulation > Advanced expressions > UNICOM Intelligence function library > List functions > SortAsc
 
SortAsc
This function returns an array containing copies of items from the input list, sorted in ascending order. The optional Count parameter defines how many items from the input list are included in the returned list.
Syntax
SortAsc(List [, Count [, IgnoreLocale]])
Parameters
List
Type: None
Array, collection, or Categorical value to operate on.
Count
Type: Long
Optional. Number of items to return. If omitted, negative, or greater than the number of input items, all items are returned.
IgnoreLocale
Type: Boolean
Optional. When True, the rules of the input locale are ignored when sorting text and the text is sorted in a language-neutral way. The default is False.
(return)
Type: None
An array consisting of a sorted copy of the input list.
Remarks
An error occurs if List is a collection that does not support the For Each...Next syntax. When List is a collection object, the return value is an array that contains copies of the objects in the collection and the input collection object is unchanged. Because the return value is an array, it does not have a Count property.
The sorting method depends on the type of the items in the list. If they are simple Long, Double, Text, Date, or Boolean values, they are sorted in ascending order. When sorting Boolean values, SortAsc considers False to be less than True.
If the items are objects, they are sorted by the value of their default property. An error occurs if the objects do not have a default property or its value cannot be determined.
The input locale is used to determine the correct ordering for text values, unless IgnoreLocale is True, when the sorting is performed in a locale-independent way. The locale-independent sort is case-sensitive and is likely to give unexpected results. When the input locale is used, the sort is always case-insensitive. Items with the same equivalent values may not appear in the same relative order in the sorted list as in the original list.
Example
The following mrScriptBasic example writes the short and long names of each language in the MDM Languages collection to a text file two times. First in the order in which they appear in the collection and then after using SortAsc to sort the collection in ascending order. The collection is sorted in ascending order of the three-character language codes stored in the Name property because it is the default property of the Language object.
Dim MyDocument, MyLanguage, Sorted

Set MyDocument = CreateObject("MDM.Document")

MyDocument.Open("C:\Program Files\IBM\SPSS\DataCollection\6\DDL\Scripts\Interview\Projects\Museum\Museum.backup.mdd", , _
MDMLib.openConstants.oREAD)

For Each MyLanguage in MyDocument.Languages
Debug.Log(MyLanguage.Name + ": " + MyLanguage.LongName)
Next

Debug.Log(" ")

Set Sorted = SortAsc(MyDocument.Languages)

For Each MyLanguage in Sorted
Debug.Log(MyLanguage.Name + ": " + MyLanguage.LongName)
Next
Here is the output:
CHS: Chinese (China)
ZHH: Chinese (Hong Kong SAR)
ENU: English (United States)
ESN: Spanish (International Sort)
JPN: Japanese
KOR: Korean
THA: Thai

CHS: Chinese (China)
ENU: English (United States)
ESN: Spanish (International Sort)
JPN: Japanese
KOR: Korean
THA: Thai
ZHH: Chinese (Hong Kong SAR)
See also
List functions