Developer Documentation Library > 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.
Syntax
SortAsc(<list> [, <count> [, <ignore_locale>]])
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.
<ignore_locale>
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 value is False.
(return)
Type: None
An array consisting of a sorted copy of the input list.
Notes
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 <igore_locale> 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 might 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\7\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)
For an example of using SortAsc when cleaning data in a DataManagementScript (DMS) file, see Example 3: More on cleaning single response data.
See also
SortDesc
List functions