ASort()
This function sorts the elements in an array. You can sort the entire array or a consecutive subset. In a two-dimensional array, sorting can be based on any column. Either ascending or descending order can be specified. Beginning in VFP 7, you can also perform case-insensitive sorts.
Usage |
nSuccess = ASORT( ArrayName [, nStartPos [, nNumElems [, nSortOrder [, nCase ] ] ] ] ) |
Parameter |
Value |
Meaning |
ArrayName |
Name |
The array to be sorted. |
nStartPos |
Negative number or omitted |
Sort the entire array. The use of any value other than –1 for this purpose is undocumented. |
Numeric |
Begin sorting at the specified element. In a two-dimensional array, sort based on the column containing nStartPos. |
|
nNumElems |
0, Negative number, or Omitted |
Sort from nStartPos to the end of the array. Note that inclusion of any value other than –1 for this purpose is undocumented. |
Positive number |
For a one-dimensional array, sort the number of elements specified. For a two-dimensional array, sort the number of rows specified. |
|
nSortOrder |
0, Negative number, or Omitted |
Sort in ascending order. |
Positive number |
Sort in descending order. |
|
nCase |
0 or Omitted |
Perform a case-sensitive sort. |
1 |
Perform a case-insensitive sort. |
|
nSuccess |
1 |
Sort successful. |
–1 |
Sort unsuccessful. We've never seen this result. |
Note that positive values for nSortOrder sort in descending order, while negative values sort in ascending order. Talk about confusing. In fact, it's so confusing that earlier versions of the Visual FoxPro Help file got it wrong. |
Example |
ADIR( aFiles, "*.DBF") && Get a list of DBFs ASORT( aFiles) && Put in name order ASORT( aFiles, 1, -1, 1) && Put in descending name order ASORT( aFiles, 2) && Put in size order ASORT( aFiles, 3, 3) && Put the first 3 rows in date order ASORT( aFiles, 18, 5) && Put the 4th through 8th rows && in date order ADIR( aFiles, "*.DBF", "*.*", 1) && DBFs with original caps ASORT( aFiles, -1, -1, -1, 1) && Case-insensitive sort |
See Also |