Results 1 to 6 of 6

Thread: [RESOLVED] Removing Deplicates Problem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Posts
    219

    Resolved [RESOLVED] Removing Deplicates Problem

    VB Code:
    1. Private Sub RemoveDuplicates(list As ListBox)
    2.     Dim i As Integer, x As Integer
    3.     For i = 0 To list.ListCount - 1
    4.         For x = 0 To list.ListCount - 1
    5.             If i <> x Then
    6.                 If list.list(i) = list.list(x) Then
    7.                     list.RemoveItem (x)
    8.                 End If
    9.             End If
    10.         Next x
    11.     Next i
    12. End Sub
    13.  
    14. Private Sub Cmdremove_Click()
    15.     Call RemoveDuplicates(List1)
    16. 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?

  2. #2
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Removing Deplicates Problem

    Why would you allow duplicates in the first place?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Posts
    219

    Re: Removing Deplicates Problem

    its not that im allowing it, im trying to remove them from a file that contains deplicates

  4. #4
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    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.

  5. #5
    Frenzied Member d3gerald's Avatar
    Join Date
    Jan 2006
    Posts
    1,348

    Re: Removing Deplicates Problem

    you can have it like this
    VB Code:
    1. Private Sub RemoveDuplicates(list As ListBox)
    2.     Dim i As Integer, x As Integer
    3.     For i = 0 To list.ListCount - 2
    4.         For x = i + 1 To list.ListCount - 1
    5.             If list.list(i) = list.list(x) Then
    6.                 list.RemoveItem (x)
    7.             End If
    8.         Next
    9.     Next
    10. 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

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Posts
    219

    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
  •  



Click Here to Expand Forum to Full Width