How-To Sort Multidimensional Array In Xojo

Jeannot Muller
Oct 5 · 2 min read

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.

Image for post
Image for post

You can download the above dummy project here:

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:

Image for post
Image for post

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.

Learn Xojo

Everything About Developing with Xojo.com

Jeannot Muller

Written by

Managing director at https://teccompanion.com, physician, founder & executive consultant, developer and blogger.

Learn Xojo

Code snippets, tips and tricks to develop like a pro with the fantastic xojo.com tool on Windows, macOS, iOS, Web and Linux

Jeannot Muller

Written by

Managing director at https://teccompanion.com, physician, founder & executive consultant, developer and blogger.

Learn Xojo

Code snippets, tips and tricks to develop like a pro with the fantastic xojo.com tool on Windows, macOS, iOS, Web and Linux

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store