 |
 |

10-21-2003, 01:18 PM
|
|
Centurion
|
|
Join Date: Mar 2003
Location: Vancouver
Posts: 102
|
|
duplicate remover
|
I know this has probably been on this site many times before but I have never seen it.
I was just wondering if there is a quick duplicate remover or if anyone can fix the one I have that works in Vb but I know wont work in ASP....you see I have populated a combo box with values from one of my fields of my access database but there are many duplicates.
Code:
Do Until oRSb.EOF
Response.Write "document.forms[1].SubCategory.options[" & iCount & "]=new Option(""" & oRSb("STATNUM") & """)" & vbnewline
iCount = iCount + 1
oRSb.MoveNext
Loop
'Remove duplicate items from listbox
Dim xx
Dim yy
Dim dupsFound
dupsFound = False
xx = 0
Do While xx < document.forms[1].SubCategory.ListCount
For yy = document.forms[1].SubCategory.ListCount - 1 To xx + 1 Step -1
If document.forms[1].SubCategory.List(yy) = document.forms[1].SubCategory.List(xx) Then
document.forms[1].SubCategory.RemoveItem yy
dupsFound = True
End If
Next yy
xx = xx + 1
Loop
%>
j
|
Last edited by alp0001; 10-22-2003 at 09:10 PM.
Reason: Added VB tags
|

10-22-2003, 06:57 PM
|
 |
Senior Contributor
|
|
Join Date: Oct 2003
Location: Chattanooga, TN USA
Posts: 1,069
|
|
try this:
Code:
for i = list1.listcount - 1 to 1 Step -1
if list.list(i) = list1.list(i-1) Then
List1.removeItem i
End If
Next
|
|

10-22-2003, 06:59 PM
|
 |
Senior Contributor
|
|
Join Date: Oct 2003
Location: Chattanooga, TN USA
Posts: 1,069
|
|
|
and o yes, amke sure your listbox is sorted.
And in your code you atre first starting with the last item in the box and comparing it the the first.... If you listbox is sorted, then it will never catch any, unless there are only 2 items!
|
|

10-22-2003, 09:02 PM
|
 |
Xtreme Tester
Retired Moderator * Expert *
|
|
Join Date: Jan 2002
Location: Round Lake Heights, IL
Posts: 2,815
|
|
Why are there duplicates in the first place? Normally when someone creates an sql statement to retrieve the appropriate recordsets (for a listbox), each dataset would be different.
Post the sql statement, give more info on your DB fields, and please use the VB tags in the future.
Edit: Illusionist: You aren't checking every value (only the previous one)
|
__________________
Avatar by the very talented member: lebb
Last edited by alp0001; 10-22-2003 at 09:08 PM.
|

10-22-2003, 09:18 PM
|
 |
Senior Contributor
|
|
Join Date: Oct 2003
Location: Chattanooga, TN USA
Posts: 1,069
|
|
|
@alp0001:
yes, but if the listbox was sorted, then the 2 duplicates, or more, would be next to each other so, if they were it would remove one.
111
222
222
333
333
running my code on that would result in:
111
222
333
|
|

10-22-2003, 09:26 PM
|
 |
Xtreme Tester
Retired Moderator * Expert *
|
|
Join Date: Jan 2002
Location: Round Lake Heights, IL
Posts: 2,815
|
|
|
What if there were three (or more) of the same value?
|
__________________
Avatar by the very talented member: lebb
|

10-22-2003, 09:29 PM
|
 |
Senior Contributor
|
|
Join Date: Oct 2003
Location: Chattanooga, TN USA
Posts: 1,069
|
|
|
it would still work as long as the listbox is sorted!
|
|

10-22-2003, 09:35 PM
|
 |
Xtreme Tester
Retired Moderator * Expert *
|
|
Join Date: Jan 2002
Location: Round Lake Heights, IL
Posts: 2,815
|
|
Doh  , reached that point of the night where I don't think straight anymore.
Also, the following will produce an error:
Code:
If list.list(i) = list1.list(i-1) Then
Should be:
If list1.list(i) = list1.list(i-1) Then
|
__________________
Avatar by the very talented member: lebb
|

10-22-2003, 09:52 PM
|
 |
Senior Contributor
|
|
Join Date: Oct 2003
Location: Chattanooga, TN USA
Posts: 1,069
|
|
|
lol, sometiems we all get that way! lol
Yes, i found that when i was testing it too make sure it would delete the dupes if there were 3 or more! hehe i just forgot to change it!
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|