SortDesc
This function returns an array containing copies of items from the input list, sorted in descending order. The optional Count parameter defines how many items from the input list are included in the returned list.
Syntax
SortDesc(<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 descending 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 <ignore_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
This example shows using SortDesc in an SQL query to sort the responses given to a multiple response question.
SELECT Respondent.Serial,
Remember,
Remember.SortDesc() AS 'Remember.SortDesc'
FROM vdata
WHERE Remember IS NOT NULL
Here is the result set for the first five respondents:
Respondent.Serial Remember Remember.SortDesc
----------------- --------------------------------- ----------------------------------
305 {31,33,34,38,39,44,18} {44,39,38,34,33,31,18}
306 {31,33,34,38,39,40,42,18} {42,40,39,38,34,33,31,18}
307 {31,34,35,36,37,38,39,42,43,44,18} {44,43,42,39,38,37,36,35,34,31,18}
308 {31,32,35,38,39,18} {39,38,35,32,31,18}
309 {31,35,39,43,44} {44,43,39,35,31}
310 {31,35,37,38,42,43,18} {43,42,38,37,35,31,18}
For an example of using SortDesc when cleaning data in a DataManagementScript (DMS) file, see Example 3: More on cleaning single response data.
See also