Before I reinvent the wheel: does anyone have a method to sort a 2-dimensional array? I have some database metadata where I can't use "order by" and need to sort the data before shoving it into a listbox.
I did some Googling but I'm lazy.
There will probably be a better idea, but here's a quick and dirty idea..
Flatten the 2D array to a 1D array by joining element 1 with element 2 as strings, split by (say) a ~ character
Sort the one-dimensional array using array.sort
Then fill your listbox using that, splitting as you go.
Or even better, use TAB as the separator, and after the sort has happened, you can just Addrow into the listbox, and the tab will make the 2 parts hit the right columns automatically..
you can make a sort method that return -1,0,1
so you put something in and out comes a value
in case of 2-dimensional array ... emm - i must test myself
ok, the array.sort method is only for one dimension ...
how about a class, you can store the instances into a array and you can sort this.
inside of this class is a property array with a list of the other dimension, you can sort this easy with the sort method
array.Sort(sortMethod As Delegate)
so your 2 dimemsion array turns into a list with each entry have a list
Examble 3 column
Is it? Programmingwise maybe. But databases are very fast with sorting. You might lose some time with importing and exporting the data. But as it is in memory, that might not make much difference. I'd be interested which approach is faster in the end.
@Beatrix W ah, that's what Markus Rauch meant. I'll try that.
Denk Dir eine Liste mit Objekten wo bei jedes Objekt auch eine Liste haben kann.
Jede Liste läßt sich über eine Vergleichsfunktion sortieren.
Ob es Dir so nützt weiß ich nicht.
Liste Obj1 Liste A B C Obj2 Liste X Y Z
Use Quicksort code written in Xojo that uses callbacks (or an Interface class), that asks you (a) to compare two values by their index, and (b) to swap two values by index. This separates the actually compared data from the the algorithm, which only needs to know which "item" is larger, without having to look at the data itself.
Assuming the first dimension are the rows, and the 2nd dimension are the columns, first sort each column individually, once.
When all cols are sorted, sort the rows.
I have some code for this, and I had published it very long ago. It should be in my old RB archive at http://files.tempel.org/RB/ or at http://www.tempel.org/RB/ but I can't find it there right now...
Ah, found it. Case still matters on the Web :) http://www.tempel.org/rb/ -- Search for "sort"