Adblock breaks this site

Adding item to a combo (Problem)

Discussion in 'Programming General' started by Visual Basic Matt, Aug 8, 2008.

  1. Visual Basic Matt

    Visual Basic Matt Apprentice

    Joined:
    Jan 29, 2008
    Posts:
    647
    Referrals:
    2
    Sythe Gold:
    56
    Discord Unique ID:
    223154494878253056
    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... ;)
     
  2. Darthatron

    Darthatron Massive Troll
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    May 22, 2006
    Posts:
    1,612
    Referrals:
    3
    Sythe Gold:
    0
    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.
     
  3. Visual Basic Matt

    Visual Basic Matt Apprentice

    Joined:
    Jan 29, 2008
    Posts:
    647
    Referrals:
    2
    Sythe Gold:
    56
    Discord Unique ID:
    223154494878253056
    Adding item to a combo (Problem)

    Thanks darth, this helped tremendously!
     
< Decompiling? | All VB6 Commands >


 
 
Adblock breaks this site