|
-
Sep 20th, 2001, 01:29 AM
#1
Thread Starter
New Member
Removing Duplicates in Lisbox
how do i remove duplicates in a listbox??? please give code ---
THANK YOU THANK YOU THANK YOU!!!!!
-
Sep 20th, 2001, 01:41 AM
#2
Fanatic Member
It is a base arithmetic.
How do you programming?????????????
-
Sep 20th, 2001, 01:46 AM
#3
Lively Member
on a form create a listbox named list1 and put the following code in a commandbox
Code:
on error resume next
for n = 0 to list1.listcount - 1 'loop the listbox
cur = list1.list(n) 'sets the current list item
for m = 0 to list1.listcount - 1 'now loop for the victims
if m <> n and list1.list(m) = cur then 'we found a match!
list1.removeitem m 'now remove it
'add more code here to execute when finding a match
end if
next m
next n
^^^ this code will look for matches by case
example: 'abc' will match with 'abc' but not 'ABC'
if you do not want it case sensitive.. modify the code above with this line:
Code:
if m <> n and ucase$(list1.list(m)) = ucase$(cur) then
^^^now it will look for matches by similarity
example: 'abc' will match with 'abc' and 'ABC'
Kid A
18 Year Old Programmer
Visual Basic 6 & .NET Enterprise, ASP, WinXP (Advanced Server) Administration, HTML, Graphic Arts, Winsock, Learning VC++ and now maybe C#.. heh
[vbcode]
'back in the day vb6 code
Private Sub My_Life()
If Hour(Now) > 3 And Hour(Now) < 13 Then
Status = "Sleeping"
Else
Status = "Computing"
End If
End Sub
[/vbcode]
-
Sep 20th, 2001, 03:05 AM
#4
PowerPoster
Hi
2 things
1) Any time u remove items from a list box you should always loop backwards. In the prev code from da404 u should change loops to ....
VB Code:
on error resume next
[b]for n = list1.listcount - 1 to 0 Step - 1 [/b] 'loop the listbox
cur = list1.list(n) 'sets the current list item
[b]for m = list1.listcount - 1 to 0 Step -1 [/b] 'now loop for the victims
if m <> n and list1.list(m) = cur then 'we found a match!
list1.removeitem m 'now remove it
'add more code here to execute when finding a match
end if
next m
next n
2) Secondly, that code will be ok for small amounts of items but if u want to remove duplicates from a large list then it is much quicker to sort the list first and then loop thru it only once removing duplicates
Regards
Stuart
-
Sep 20th, 2001, 11:22 AM
#5
beachbum: Nice little routine. I have something that I did to do this, but your routine is much, much tighter.
-
Sep 20th, 2001, 05:53 PM
#6
PowerPoster
Hi Hack
I didnt write that routine... only modified it to work. It was da404's.
regards
Stuart
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
|