-
Random Sort
Hi all,
Good day. I am facing a problem here in sorting. I has a list of ID selected from database. The list of ID is the following:
AH
AJ
AP
AW
AZ
How can I sort the ID where the ID that I select should be always on top, then only sort by ascending?
For example, I select AP. So the sorting should be like this:
AP, AH,AJ,AW,AZ
-
Re: Random Sort
p,h,j,w.z ?? Not alphabetical...
-
Re: Random Sort
loop through the list and find your item, and place it in the first position, then pass the list to a sort routine that has been set to sort from the second item...
IE: Classic sort
Code:
For Loop1 = 2 to List.Length -1 ' Traditional is 1 to Length -1
For Loop2 = Loop1 +1 to length
if List(Loop1) < List(Loop2) then Swap ( List(Loop1) , List(Loop2))
Next Loop2
Next Loop1
-
Re: Random Sort
Remove the selected item from your list and hold it. Order the remaining list then Insert the held item at position zero
-
Re: Random Sort
Probably want to reverse the outer loop.
Code:
For Loop1 = List.Length -1 to 2 Step -1