|
-
Sep 17th, 2004, 11:16 AM
#1
Thread Starter
Fanatic Member
listbox sort by length ?
I am using a list box to grab a bunch of names that will be
use as a replace list... issue is if you have something like
grab_proc and grap_proc_name and you do a replace with
with lets say g_grab_proc you end up getting
a double hit on grab_proc_name..
so if I can sort the list to longest to shortest I think it will fix
it.... and I cant just name the replace use a space afterwards to
fix it..
any ideas ??
-
Sep 17th, 2004, 11:48 AM
#2
So then, do you just want to sort your ListBox in terms of string length instead of ASCII sorting (which is built into the control)?
-
Sep 17th, 2004, 12:11 PM
#3
Thread Starter
Fanatic Member
yep.. thats it... Not by A-Z or what not...
I could write code to do it.. just wondering if there
was some way to change the sort criteria...
or someone had quick code snipit to do it..
-
Sep 17th, 2004, 02:53 PM
#4
Here is a quick sample for you, Kevin:
VB Code:
Public Sub SortByLength(lst As ListBox)
'=======================================
Dim i&, j&, tmpValue
Dim arTemp() As String
Debug.Print "Start Time: " & Format(Now, "hh:nn:ss")
ReDim arTemp(lst.ListCount - 1)
For i = 0 To lst.ListCount - 1
arTemp(i) = lst.List(i)
Next i
lst.Clear
For i = 0 To UBound(arTemp)
For j = i To UBound(arTemp)
If Len(arTemp(i)) > Len(arTemp(j)) Then
tmpValue = arTemp(j)
arTemp(j) = arTemp(i)
arTemp(i) = tmpValue
End If
Next
lst.AddItem arTemp(i)
Next
Debug.Print "End Time: " & Format(Now, "hh:nn:ss")
End Sub
-
Sep 17th, 2004, 03:16 PM
#5
PowerPoster
Debug.Print "Start Time: " & Format(Now, "hh:nn:ss")
What does Now do?
the rest is easy, I aint never seen that Now used before
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
-
Sep 17th, 2004, 03:48 PM
#6
-
Sep 17th, 2004, 04:14 PM
#7
Originally posted by dglienna
returns system time
To be exact: System Date and Time
-
Sep 17th, 2004, 06:37 PM
#8
Lively Member
I have used a recursive QuickSort (which you can probably do a Goolge on) for sorting. I pass a variable through hte Sort function to a CompareFunction that lets you have variable methods of Sorting/Comparing without the need for a different sort for each.
1 = Sort by Length,
2 = Sort Alphabetically
3 = ...
HTH
Hume
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
|