Xbasic

SORT_ARRAY Function

Syntax

N SORT_ARRAY(C array_name[,N sort_options])

Arguments

array_name

A character string containing the name of the array.

sort_options

Optional. Default = Sort ascending. 1 = Sort descending.

Description

Sort the elements of an array.

Discussion

SORT_ARRAY() sorts the specified character, numeric, or date array. The Array_Name parameter is a character string containing the name of the array. The default sort order is ascending order. Set the optional Sort Options parameter to 1 to sort in descending order. Note : SORT_ARRAY() is documented for backward compatibility only. It has been replaced by the <ARRAY>.SORT() method.

Example 

Fills the color array and then sorts the values in both ascending and descending order.

dim color[3] as C
Color[1] = "Red"
Color[2] = "Blue"
Color[3] = "Green"
sort_array("color")
for i = 1 to 3
    trace.writeln(color[i] )
next i
sort_array("color", 1)
for i = 1 TO 3
    trace.writeln(color[i] )
next i

Same as above, but uses the <ARRAY>.SORT()method.

dim color3 as C
Color[1] = "Red"
Color[2] = "Blue"
Color[3] = "Green"
Color.sort()
for i = 1 TO 3
    trace.writeln(color[i] )
next i
Color.sort(.f.)   'descending sort
for i = 1 TO 3
    trace.writeln(color[i] )
next i

See Also