In Xojo it is easy to sort one-dimensional arrays. You just write: yourArray.Sort and you are done.
Things are getting a little bit more complicated, if you have to sort so-called multidimensional arrays, means an array with multiple values. Out-of-the-box Xojo can’t sort these arrays.
But with a simple re-design of your application it is relatively easy to get this achieved. You can store your values in an own class, and the instances of that class in an one-dimensional array.
Now Xojo can’t sort this one-dimensional array either, because it contains classes and not strings for instance, but you can write an own method to sort your array, as I will show below.
You can download the above dummy project here:
You can't perform that action at this time. You signed in with another tab or window. You signed out in another tab or…
The main code is straight forward:
Please note that we are writing an own method to sort our one-dimensional array, containing the class instances. This is done via the command:
results.sort(addressof vehicleCompareCar )
VehicleCompareCar is the methodname to do this sorting, which again is straightforward:
I decided to sort by car type in this example, but of course I could easily sort by whatever other field I’m interested in.
In conclusion: if you are in the need of sorting a multidimensional array with Xojo, it is best to convert it first into class instances which you put into a one-dimensional array.