Results 1 to 8 of 8

Thread: removing duplicate items in list

  1. #1

    Thread Starter
    Hyperactive Member Abdulrahman's Avatar
    Join Date
    Oct 2000
    Location
    Scotland
    Posts
    281

    removing duplicate items in list

    hi all,

    I have a list box with a few 1000s items in it.. there are many duplicate items in it.. some several times actaully.

    how can I remove all duplicates from the list.

    thanks a lot guys!
    Abe
    1+1=3
    make life simple, use a calculator!

  2. #2
    Lively Member
    Join Date
    Mar 2001
    Location
    *.*
    Posts
    85
    I'd suggest passing all the elements into an array, use some sort of bubble sort to put only unique items into another array and finally, after deleting all elements in the combo box, populate the combo box with the entries from the second array
    Everytime

    "I'm not normally a religious man, but if you're up there, save me, Superman!" Homer Simpson

    Visit my site

  3. #3
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    How is this data being loaded to the listbox?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  4. #4

    Thread Starter
    Hyperactive Member Abdulrahman's Avatar
    Join Date
    Oct 2000
    Location
    Scotland
    Posts
    281

    re:

    thanks guys

    it will be populated via database..

    however.. at the moment I just put a bunch of "list1.additem XXXX" in the load form event as a demo...

    any advise?

    cheers
    Abe
    1+1=3
    make life simple, use a calculator!

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    A simple little loop should do the trick nicely.
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim i As Long
    3. Dim j As Long
    4.     With List1
    5.         For i = 0 To .ListCount - 1
    6.             For j = .ListCount To (i + 1) Step -1
    7.                 If .List(j) = .List(i) Then
    8.                     .RemoveItem j
    9.                 End If
    10.             Next
    11.         Next
    12.     End With
    13.  
    14. End Sub

  6. #6
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046

    Re: re:

    Originally posted by Abdulrahman
    thanks guys

    it will be populated via database..

    however.. at the moment I just put a bunch of "list1.additem XXXX" in the load form event as a demo...

    any advise?

    cheers
    Abe
    cant you just filter out the duplicates when you query the db?

  7. #7
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Re: re:

    Originally posted by Abdulrahman
    thanks guys

    it will be populated via database..

    however.. at the moment I just put a bunch of "list1.additem XXXX" in the load form event as a demo...

    any advise?

    cheers
    Abe
    Couldn't you load as DISTNCT?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  8. #8

    Thread Starter
    Hyperactive Member Abdulrahman's Avatar
    Join Date
    Oct 2000
    Location
    Scotland
    Posts
    281

    re:

    Thanks a lot!!!

    damn why did I not think of that!

    my brain gets dizzy when I get into nested loops....



    Abe
    1+1=3
    make life simple, use a calculator!

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