Table Of Contents | Index |
Example:A common use of this command is sorting a 2 dimensional array by one of it's key fields. Suppose you wanted to sort by the second field. Here's how you might do it.
var Data NameListReadAscTextFile('PHONE.LST',Data) MatrixInvert Data NameList = Data[1] ;makes an array from field 1
Example:
var Customers NamesCustomers[1] = Set[200,"Joe","888-5329"] Customers[2] = Set[201,"Adam","866-9823"] Customers[3] = Set[202,"Kate","862-9236"] ; The above creates a 2-dimensional array called Customers
MatrixInvert Customers ; here, the array is inverted Names = Customers[2] MatrixInvert Customers ; here, the array is reinverted SortArrayLinked(Customers,Names) ;the array Customers is sorted alphabetically by Names Loop Customers Loop LoopVal Write LoopVal ' ' ; the values of the array Customers is printed out EndLoop Writeln EndLoop
In the above example, the result is: 201 Adam 866-9823 200 Joe 888-5329 202 Kate 862-9236
The MatrixInvert will take a matrix like: 200 Joe 888-5329 201 Adam 866-9823 202 Kate 862-9236
and invert it to: 200 201 202 Joe Adam Kate 888-5329 866-9823 862-9236
See Also: | SortArrayLinked |
---|
Category: | Array |
---|
Table Of Contents | Index |
|