|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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! |
|
#3
|
|||
|
|||
|
Oops...you wanted this for a listbox....should more or less be the same code.
|
|
#4
|
|||
|
|||
|
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
. |
|
#5
|
|||
|
|||
|
Listbox -remove duplicate items
Thanks I will try that and see if it works.
|
|
#6
|
|||
|
|||
|
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. |
|
#7
|
|||
|
|||
|
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?
|
|
#8
|
|||
|
|||
|
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! |
|
#9
|
|||
|
|||
|
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.
|
|
#10
|
|||
|
|||
|
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 |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > ListBox |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|