-
May 2nd, 2013, 11:16 PM
#1
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
-
May 3rd, 2013, 01:02 AM
#2
Re: Random Sort
p,h,j,w.z ?? Not alphabetical...
-
May 3rd, 2013, 01:11 AM
#3
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
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
May 3rd, 2013, 10:43 AM
#4
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
-
May 3rd, 2013, 03:12 PM
#5
Re: Random Sort
Probably want to reverse the outer loop.
Code:
For Loop1 = List.Length -1 to 2 Step -1
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|