|
-
Mar 21st, 2006, 10:33 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Removing Deplicates Problem
VB Code:
Private Sub RemoveDuplicates(list As ListBox)
Dim i As Integer, x As Integer
For i = 0 To list.ListCount - 1
For x = 0 To list.ListCount - 1
If i <> x Then
If list.list(i) = list.list(x) Then
list.RemoveItem (x)
End If
End If
Next x
Next i
End Sub
Private Sub Cmdremove_Click()
Call RemoveDuplicates(List1)
End Sub
this is what im using to remove duplicates from listbox but if i have for example three A's and 3 B's and when i click to deduple it will only remove one A and one B so i would still have some duped to fix this i would have to keep on clicking dedupe how can i fix this?
-
Mar 21st, 2006, 10:46 PM
#2
Re: Removing Deplicates Problem
Why would you allow duplicates in the first place?
-
Mar 21st, 2006, 10:49 PM
#3
Thread Starter
Addicted Member
Re: Removing Deplicates Problem
its not that im allowing it, im trying to remove them from a file that contains deplicates
-
Mar 21st, 2006, 10:52 PM
#4
Re: Removing Deplicates Problem
Well, in that case use a listbox with the sorted property set to true. Loop thru the data starting at the end to the beginning. In this way when you remove something the indexes are not reset.
You will only have to go thru the list once.
-
Mar 21st, 2006, 10:53 PM
#5
Frenzied Member
Re: Removing Deplicates Problem
you can have it like this
VB Code:
Private Sub RemoveDuplicates(list As ListBox)
Dim i As Integer, x As Integer
For i = 0 To list.ListCount - 2
For x = i + 1 To list.ListCount - 1
If list.list(i) = list.list(x) Then
list.RemoveItem (x)
End If
Next
Next
End Sub
On error goto Trap
Trap:
in case of emergency, drop the case...
****************************************
If this post has been resolved. Please mark it as "Resolved" by going through the "Thread Tools" above and clicking on the "Mark Thread Resolved " option. if a post is helpful to you, Please Rate it by clicking on the Rate link right below the avatar
-
Mar 21st, 2006, 10:54 PM
#6
Thread Starter
Addicted Member
Re: Removing Deplicates Problem
yay it works didnt know it was that easy lol thank you!
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
|