Go Back  Xtreme Visual Basic Talk > Other Languages > Web Programming > duplicate remover


Reply
 
Thread Tools Display Modes
  #1  
Old 10-21-2003, 01:18 PM
jmjoseph jmjoseph is offline
Centurion
 
Join Date: Mar 2003
Location: Vancouver
Posts: 102
Default 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
Reply With Quote
  #2  
Old 10-22-2003, 06:57 PM
Illusionist's Avatar
Illusionist Illusionist is offline
Senior Contributor
 
Join Date: Oct 2003
Location: Chattanooga, TN USA
Posts: 1,069
Default

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
Reply With Quote
  #3  
Old 10-22-2003, 06:59 PM
Illusionist's Avatar
Illusionist Illusionist is offline
Senior Contributor
 
Join Date: Oct 2003
Location: Chattanooga, TN USA
Posts: 1,069
Default

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!
Reply With Quote
  #4  
Old 10-22-2003, 09:02 PM
alp0001's Avatar
alp0001 alp0001 is offline
Xtreme Tester

Retired Moderator
* Expert *
 
Join Date: Jan 2002
Location: Round Lake Heights, IL
Posts: 2,815
Default

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.
Reply With Quote
  #5  
Old 10-22-2003, 09:18 PM
Illusionist's Avatar
Illusionist Illusionist is offline
Senior Contributor
 
Join Date: Oct 2003
Location: Chattanooga, TN USA
Posts: 1,069
Default

@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
Reply With Quote
  #6  
Old 10-22-2003, 09:26 PM
alp0001's Avatar
alp0001 alp0001 is offline
Xtreme Tester

Retired Moderator
* Expert *
 
Join Date: Jan 2002
Location: Round Lake Heights, IL
Posts: 2,815
Default

What if there were three (or more) of the same value?
__________________
Avatar by the very talented member: lebb
Reply With Quote
  #7  
Old 10-22-2003, 09:29 PM
Illusionist's Avatar
Illusionist Illusionist is offline
Senior Contributor
 
Join Date: Oct 2003
Location: Chattanooga, TN USA
Posts: 1,069
Default

it would still work as long as the listbox is sorted!
Reply With Quote
  #8  
Old 10-22-2003, 09:35 PM
alp0001's Avatar
alp0001 alp0001 is offline
Xtreme Tester

Retired Moderator
* Expert *
 
Join Date: Jan 2002
Location: Round Lake Heights, IL
Posts: 2,815
Default

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
Reply With Quote
  #9  
Old 10-22-2003, 09:52 PM
Illusionist's Avatar
Illusionist Illusionist is offline
Senior Contributor
 
Join Date: Oct 2003
Location: Chattanooga, TN USA
Posts: 1,069
Default

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!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to create duplicate error?? elleetan Database and Reporting 1 09-17-2003 03:32 AM
Duplicate value error in database airski Database and Reporting 1 06-03-2003 12:23 PM
Finding Duplicate Values dnd Excel 4 05-22-2003 12:53 PM
Check for duplicate values Dynamically? The Cleaner Database and Reporting 3 08-16-2001 12:22 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->