Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old July 15th, 2004, 01:32 PM
QueenVBA QueenVBA is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 22 QueenVBA User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 43 sec
Reputation Power: 0
ListBox - VB remove Duplicates!

How do you remove duplicate item from a list box? I need to leave one item with that name at a time. listbox example:
Tent
Tent
Tent
Tent
Tent
Tent
Tent
Green
Green
Green
Green
Green
Green
Green
Green
Want to remove all the tents except one and all the greens except 1

Last edited by QueenVBA : July 15th, 2004 at 01:48 PM. Reason: add to title

Reply With Quote
  #2  
Old July 15th, 2004, 01:52 PM
spak111 spak111 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 349 spak111 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 25 sec
Reputation Power: 5
Send a message via AIM to spak111
You need to use a psuedo control break:
Code:
	
Dim strTemp As String
	Dim i As Integer
	Do While i <= ComboBoxName.ListCount
		If strTemp = Combo1.List(i) Then
			ComboBoxName.RemoveItem (i)
		Else
			strTemp = ComboBoxName.List(i)
			i = i + 1
		End If
	Loop


I hope this helps you!

Reply With Quote
  #3  
Old July 15th, 2004, 01:53 PM
spak111 spak111 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 349 spak111 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 25 sec
Reputation Power: 5
Send a message via AIM to spak111
Oops...you wanted this for a listbox....should more or less be the same code.

Reply With Quote
  #4  
Old July 15th, 2004, 01:55 PM
spak111 spak111 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 349 spak111 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 25 sec
Reputation Power: 5
Send a message via AIM to spak111
Yep, it does, the code works the same way for a combo box or for a list box. Just pretend I used ListBoxName instead of ComboBoxName .

Reply With Quote
  #5  
Old July 15th, 2004, 03:44 PM
QueenVBA QueenVBA is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 22 QueenVBA User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 43 sec
Reputation Power: 0
Listbox -remove duplicate items

Thanks I will try that and see if it works.

Reply With Quote
  #6  
Old July 15th, 2004, 03:53 PM
spak111 spak111 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 349 spak111 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 25 sec
Reputation Power: 5
Send a message via AIM to spak111
Let me know if it does. It should, it works with my computer anyway . If you do have any further problems feel free to ask.

Reply With Quote
  #7  
Old July 15th, 2004, 04:06 PM
QueenVBA QueenVBA is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 22 QueenVBA User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 43 sec
Reputation Power: 0
Thumbs up listbox

Thanks guys, it worked. It removed all the duplicate items but when it gets to the end i keep getting this message "could not get the List property. invalid property array index" after it end I think it is looking for the last item on the list and can not find it. How do i solve this?


Reply With Quote
  #8  
Old July 15th, 2004, 04:13 PM
spak111 spak111 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 349 spak111 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 25 sec
Reputation Power: 5
Send a message via AIM to spak111
Okay, not really a solution, but you shouldn't get the error anymore:

On Error ResumeNext

Hope this helps...I didn't get that when I did it. I wonder why? But this should help!

Reply With Quote
  #9  
Old July 16th, 2004, 08:21 AM
QueenVBA QueenVBA is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 22 QueenVBA User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 43 sec
Reputation Power: 0
thanks. I have other errors that need to be handled different in the same code. I will use that in a case else statement for that that error.

Reply With Quote
  #10  
Old July 16th, 2004, 09:46 AM
QueenVBA QueenVBA is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 22 QueenVBA User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 43 sec
Reputation Power: 0
my text file was about 10000 lines so it was hard to figure out where the error was
I finally figured out that once counter was equal to lstbox error occurs It hang up there even when:

On Error Resume Next

was added. Modified code, works perfect.
Dim varI As Integer
Dim strTemp As String
Do While varI <= lstCategory.ListCount
If varI = lstCategory.ListCount Then
Exit Sub
End If
If strTemp = lstCategory.List(varI) Then
lstCategory.RemoveItem (varI)
intK = intK + 1
Else
strTemp = lstCategory.List(varI)
varI = varI + 1

End If
Loop

Last edited by QueenVBA : July 16th, 2004 at 09:51 AM. Reason: included wrong part of code

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > ListBox


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway