[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?
Re: Removing Deplicates Problem
Why would you allow duplicates in the first place?
Re: Removing Deplicates Problem
its not that im allowing it, im trying to remove them from a file that contains deplicates
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.
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
Re: Removing Deplicates Problem
yay it works didnt know it was that easy lol thank you!