12-21-2023, 06:08 PM
When I have a small list of strings to sort I usually use this simple bubble sort. It's not fast but with small arrays of strings it's not even noticeable.
Code: (Select All)
'simple bubble sort
DIM Outer AS LONG ' outer loop counter
DIM Inner AS LONG ' inner loop counter
DIM StringList(100) AS STRING ' an array of strings
FOR Outer = 1 TO UBOUND(StringList) - 1 ' loop array size-1
FOR Inner = 1 TO UBOUND(stringlist) - Outer ' loop remaining indexes
IF UCASE$(StringList(Inner)) > UCASE$(StringList(Inner + 1)) THEN ' is next index smaller?
SWAP StringList(Inner), StringList(Inner + 1) ' yes, swap indexes (bubble up)
END IF
NEXT Inner
NEXT Outer