|
-
Apr 19th, 2002, 07:50 AM
#1
Thread Starter
Hyperactive Member
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!
-
Apr 19th, 2002, 07:56 AM
#2
Lively Member
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
-
Apr 19th, 2002, 07:57 AM
#3
PowerPoster
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....
-
Apr 19th, 2002, 08:00 AM
#4
Thread Starter
Hyperactive Member
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!
-
Apr 19th, 2002, 08:03 AM
#5
A simple little loop should do the trick nicely. 
VB Code:
Private Sub Command1_Click()
Dim i As Long
Dim j As Long
With List1
For i = 0 To .ListCount - 1
For j = .ListCount To (i + 1) Step -1
If .List(j) = .List(i) Then
.RemoveItem j
End If
Next
Next
End With
End Sub
-
Apr 19th, 2002, 08:05 AM
#6
PowerPoster
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?
-
Apr 19th, 2002, 08:05 AM
#7
PowerPoster
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....
-
Apr 19th, 2002, 08:06 AM
#8
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|