Gord ...
Instead of removing dupes, why not not add them in the first place. Try
this ...
Private Const LB_FINDSTRINGEXACT = &H1A2
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Sub AddToUniqueList(sListItem As String)
If SendMessage(List1.hwnd, _
LB_FINDSTRINGEXACT, _
-1, _
ByVal sListItem) = -1 Then
List1.AddItem sListItem
End If
End Sub
Private Sub Command1_Click()
AddToUniqueList "apple"
AddToUniqueList "apple"
AddToUniqueList "pear"
AddToUniqueList "apple"
AddToUniqueList "lemon"
AddToUniqueList "apple"
AddToUniqueList "orange"
AddToUniqueList "orange"
End Sub
If you need to add itemdata as well, just pass as an additional parameter
...
Private Sub AddToUniqueList(sListItem As String, nValue As Long)
If SendMessage(List1.hwnd, _
LB_FINDSTRINGEXACT, _
-1, _
ByVal sListItem) = -1 Then
List1.AddItem sListItem
List1.ItemData(List1.NewIndex) = nValue
End If
End Sub
Private Sub Command1_Click()
Call AddToUniqueList("apple", 123)
Call AddToUniqueList("apple", 123)
Call AddToUniqueList("pear", 234)
Call AddToUniqueList("apple", 123)
Call AddToUniqueList("lemon", 555)
Call AddToUniqueList("apple", 123)
Call AddToUniqueList("orange", 898)
Call AddToUniqueList("orange", 898)
End Sub
--
Randy Birch
MVP Visual Basic
http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.
*** If you call the Sleep API in Bill's latest, will it have .NET dreams?
***
> Jennifer, thank you for the input, it was just what I needed:)
> > Gordon,
> > I would not put duplicates in the combo box to start with. Before you
> > add something, check to see if it is already there. Here's some
> > simple code as an example.
> > HTH,
> > Jennifer
> > Private Sub Command1_Click()
> > Dim sList(0 To 4) As String
> > Dim X As Integer
> > sList(0) = "apple"
> > sList(1) = "orange"
> > sList(2) = "pear"
> > sList(3) = "apple"
> > sList(4) = "lemon"
> > For X = 0 To UBound(sList)
> > If bInCombo(sList(X)) = False Then
> > Combo1.AddItem sList(X)
> > End If
> > Next X
> > End Sub
> > Private Function bInCombo(sItem As String) As Boolean
> > Dim X As Integer
> > For X = 0 To Combo1.ListCount - 1
> > If sItem = Combo1.List(X) Then
> > bInCombo = True
> > Exit Function
> > End If
> > Next X
> > bInCombo = False
> > End Function
> > > Hey I'm having a difficult time figuring out the algorythm for
removing
> > > duplicate values in a combo box, could anyone help me out? I have
> arlready
> > > loaded the combo box but now want to remove any dups. Or should I not
> add
> > > the dups as I load it, and if so, what is the algorythm for that? I
> have
> > > three combo boxes I want to clean up, so do can I do it at the same
time
> or
> > > one at a time?
> > > thanks for any help.
> > > Gordy