Reverse Sorting a ListBox

I had this question years ago, then saw it again some days ago…

And, yesterday was the day to try to implement it.

I am quite sure some people will not like the code I share below, but it is a working solution (and probably need some more work).

Here I go.

The idea was to use SQLite to do the job, but I failed to find something usefull. Not that it is impossible: I was not able to do it.

Then I wanted to use a custom sort. Unfortunately the examples I saw were based on the same design (the documentation is the same sincce 1998).

At last, I was creative. Jean-Yves unlocked my brains some days ago (about drawing currency values), probably.

The idea was to add Column 0 contents in z-a order in an appended column, then sort in that column ! And that works !

So, Strasburg (in Column 0) become grubsartS (in the last Column)…

Code:

Function RowComparison(row1 as Integer, row2 as Integer, column as Integer, ByRef result as Integer) Handles RowComparison as Boolean
// a. Copy Comlum 0 strings into LB.ColumnCount in REVERSE ORDER… (right to left)
Var Sort_Col As Integer = LB.ColumnCount - 1
Var Row_Cnt As Integer = LB.RowCount - 1
Var Loop_Idx As Integer
Var rOrder As Integer // Loop Indice for the reverse order
Var Text_Cell As String // A-Z City Name
Var Cell_Text As String // Z-A City Name

// Scan All City Names
For Loop_Idx = 0 To Row_Cnt
// Get a City Name
Cell_Text = LB.CellTextAt(Loop_Idx,0)

// Reverse the order to z-a
For rOrder = Len(Cell_Text) DownTo 0
  Text_Cell = Text_Cell + Cell_Text.Middle(rOrder,1)
Next

// Add the reversed string into the last Column
LB.CellTextAt(Loop_Idx,Sort_Col) = Text_Cell

// Clears the variable contents
Text_Cell = ""

Next
End Function

The code can be set in a button;
yopu can either hide or delete the last column once the sort is done.

Nota: the values in the ID column is a simple Row #, nothing else since the original DB does not have (apparently) a Unique ID (I do not checked: too busy).

Here’s two screen shots:

a. The poopulated ListBox from the Data Base:

b. The ListBox contents after the sort:

The new documentation is very nice looking, but very poor for the power reader. As an example, you cannot make a search in the displayed text window !

Asking if I want to use the local documentation when internet is not available is very… nice. Thank you.

BTW: why do I missed that feature, years ago ? It is a mystery: I completely forgot. And I do not asked our Italian friend who need this feature why he need it.