SortWith
From Xojo Documentation
You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site! |
Contents
Description
Sorts one or more additional arrays in the same order as the base array. The sort is in ascending order.
Syntax
array.Sortwith(array1[,...arrayN])
Part | Description |
---|---|
array | The array to be sorted. |
array1 | The array to be sorted in the order determined by sorting the base array.
Array1 must have the same number of elements as the base array but can be of another data type. If the number of elements does not match, an OutOfBoundsException is thrown. |
array2...arrayN | Optional. Additional arrays to be sorted with the base array.
These arrays must also have the same number of elements as the base array but can be of different data types. |
Notes
The base array used with the Sortwith method works with Integer, string, single, and double arrays only. It accepts only one-dimensional arrays and it should have non-unique values.Results are undefined when the elements of the base array are not unique, i.e., elements of the base array are all of the same integer value.
Sortwith is ideal for sorting all the columns of a data table by one of its columns. For example, if you have a set of three arrays that store Names, Addresses, and Phone numbers of a group of people, you can sort the data table by Name by specifying the Names array as the base array and pass the Address and Phone number arrays as the parameters.
Examples
This example sorts the columns of the data table by the values in the aNames array.
aNames=array("Mozart","Bing","Jackson","Flintstone")
aAddresses=array("34 Pickwick","3424 Kenwood","432 Marlboro","1 Hardrock")
aPhones=array("234-3700","697-5300","753-2500","None")
aNames.Sortwith(aAddresses,aPhones)
//display the sorted arrays in a Listbox to verify the sort
ListBox1.addrow aNames(i)
ListBox1.cell(Listbox1.LastIndex,1) =aAddresses(i)
ListBox1.cell(ListBox1.LastIndex,2)= aPhones(i)
Next
|
See Also
Dim statement; Array, Join, Split, Ubound functions; Append, IndexOf, Insert, Pop, Redim, Remove, Shuffle, Sort methods; ParamArray keyword.