|
-
Jun 16th, 2000, 02:05 AM
#1
Here's the code:
Code:
Sub remove_dupe_list(lst As ListBox)
For a = 0 To (lst.ListCount - 1)
X$ = LCase(lst.List(a))
For b = 0 To (lst.ListCount - 1)
Y$ = LCase(lst.List(b))
If a <> b And X$ Like Y$ Then lst.RemoveItem b
Next b
Next a
End Sub
But when I use it, my program freezes. Anyone have a better code or can fix it?
-
Jun 16th, 2000, 02:28 AM
#2
Hyperactive Member
Why exactly are you using the 'Like' operator. I'm assuming you want to remove all of the dups in the list. You are already making the comparision with lower case so you should just use the '=' operator. Also, try placing a 'DoEvents' after your item remove.
-
Jun 16th, 2000, 02:30 AM
#3
Hyperactive Member
Also, you can use the 'LCase$()' function instead of the 'LCase()' function. It is much faster.
-
Jun 16th, 2000, 02:41 AM
#4
Did everything you said..nothing worked. I even put a timout .01 in there and it still freezes.
-
Jun 16th, 2000, 03:13 AM
#5
Hyperactive Member
Step through it with the debugger. What you are trying to do is risky cuz you are resizing an array in a loop that depends on the array size. It's pretty bad coding practice to do this. What you might want to try and do is build a temp list of all bins you want to remove from the list. Then in another loop call your remove on those specfic list items.
-
Jun 16th, 2000, 09:38 AM
#6
You know what I don't understand? The removing duplicates from a list works with a combo box but not a list box. Wonder why that is?
-
Jun 16th, 2000, 10:03 AM
#7
New Member
uh.. I remove dupes in list boxes all the time.. And I do it pretty much like you do and it works fine:
Code:
Private Sub Command1_Click()
Dim i As Integer
Dim j As Integer
For i = 0 To List1.ListCount - 1
If i = List1.ListCount Then Exit Sub
For j = 0 To List1.ListCount - 1
If j <> List1.ListCount Then
If LCase$(List1.List(i)) = LCase$ _
(List1.List(j)) And i <> j Then
List1.RemoveItem (j)
j = 0
End If
End If
Next j
Next i
End Sub
That should do you... you don't need DoEvents in there unless you're dupe checking big lists.
-Reprise
"Hello, I would like to buy a fish licence please..."
-
Jun 16th, 2000, 12:03 PM
#8
Member
Dim x As Single
Dim y As Single
Dim z As Single
z = 1
For x = 0 To List1.ListCount - 1
For y = z To List1.ListCount - 1
If List1.List(x) = List1.List(y) Then List1.RemoveItem y
Next y
z = z + 1
Next x
This'll remove any duplicates you might have.....if you want to remove both of them from the list, add :List1.RemoveItem x, after List1.RemoveItem y
Hope that helps...
-
Jun 16th, 2000, 12:26 PM
#9
New Member
Uh.. Darknight, your code misses duplicates in the last two positions of the listbox.
-Reprise
"Hello, I would like to buy a fish licence please..."
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
|