• Log in or sign up for an account here: https://www.sythe.org/login

Adding item to a combo (Problem)

Visual Basic Matt

Apprentice
Joined
Jan 29, 2008
Sythe Gold
56
Messages
647
Location
Evurar
Adding item to a combo (Problem)
Im trying to make it in my program so when you search something it will add to the combo. I know how to do that but, how would I make it so it only adds the item once. Like if someone searches the word Cat more than once it wont be added twice.
If the combo already has that item then not to add it again.
Please, I can take all help possible... ;)
 
Adding item to a combo (Problem)
Scan through the combobox to see if that text is in it yet... Like so...

Presuming the combobox is called Combo1:

Code:
Dim i As Long
Dim strAdding As String

'Stuff before adding the item.

strAdding = 'Whatever you're going to add.

For i = 0 To (Combo1.ListCount - 1)
    If Combo1.List(i) = strAdding Then
        Goto EndNow
    End If
Next i

Combo1.AddItem strAdding

EndNow:

'Stuff after adding the item.

-----------

What that does is loop through your Combo1 combobox, and if it finds the String you're searching for then it skips adding the string to combobox. If nothing is found it continues as normal.
 
Runescape Gamblingrunescape gambling
Back
Top