Re: Add item to Combo Box?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Jan Hyde (StellaDrinker_at_REMOVE.ME.uboot.com)
Date: 09/14/04


Date: Tue, 14 Sep 2004 09:05:59 +0100

Milo <Milo@Freenet.co.uk>'s wild thoughts were released on
Mon, 13 Sep 2004 17:09:53 +0100 bearing the following fruit:

>Jan Hyde wrote:
>> Milo <Milo@Freenet.co.uk>'s wild thoughts were released on
>> Mon, 13 Sep 2004 16:20:47 +0100 bearing the following fruit:
>>
>>
>>>Jan Hyde wrote:
>>>
>>>
>>>>"Damon" <nonsense@nononsense.com>'s wild thoughts were
>>>>released on Mon, 13 Sep 2004 14:13:54 GMT bearing the
>>>>following fruit:
>>>>
>>>>
>>>>
>>>>>Hi,
>>>>>
>>>>>I am using VB6 and would like to be able to add an item to a combo box. I
>>>>>know that I can use the .additem but I need to be able to search the
>>>>>contents of the combo box to see if the value is already in there and if not
>>>>>add the item. I know there is Matchedtolist for a datacombo but how can I
>>>>>do this for a regular combo box?
>>>>>
>>>>>Would appreciate the help.
>>>>
>>>>
>>>>Use API calls
>>>>
>>>>http://vbnet.mvps.org/
>>>>
>>>>
>>>>
>>>>Jan Hyde (VB MVP)
>>>>
>>>
>>>use a loop, much easier than API.
>>
>>
>> Easier?!
>>
>>
>>> Dim bExist As Boolean
>>>
>>> bExist = False
>>>
>>> If Combo1.ListCount > 0 Then
>>> For i = 0 To Combo1.ListCount
>>
>>
>> Why not loop from 0 to Combo1.listcount -1 and save an
>> interation.
>>
>>
>>
>>> Combo1.ListIndex = i - 1
>>
>>
>> Then the above line isn't needed. The other reason the above
>> line could be very bad is that it fires the click event
>> which it turn could severely impare the performance of your
>> routine.
>>
>> J
>>
>>
>>> If Combo1.Text = Text1.Text Then '''change
>>>text1.text to additem source
>>> bExist = True
>>> End If
>>> Next i
>>> Else
>>> Combo1.AddItem Text1.Text '''change
>>>text1.text to additem source
>>> Exit Sub
>>> End If
>>>
>>> If bExist = False Then
>>> Combo1.AddItem Text1.Text '''change
>>>text1.text to additem source
>>> Else
>>> MsgBox "Item already in list!" '''add woteva
>>>happens here
>>> End If
>>>
>>>
>>>
>>>hope this helps....milo
>>
>>
>>
>> Jan Hyde (VB MVP)
>>
>come on guys, im only trying to help! at least it works! I think doing a
>loop like this is easier, well for the noobies anyway. Otherwise they
>have to learn the ways of the API. Unless they just wanna do a copy
>paste project.
>
>Oh well, nice to see a friendly environment!
>

Don't take my comments as critisism. See it as constructive
discusion. You must remember that these posts will be around
for years to come and pointing out any potential pitfalls
could save someone a lot of time in the future.

If I make a post for example, one of the other regulars may
follow it up with a comment that I'm fully aware of. They do
it not for my benefit but for the benefit of anyone else who
may read the thread.

This *is* a friendly environment and don't let my comments
put you of posting. We will comment on code that is posted
because it is a learning experience for all.

As far as APIs go, many are very simple to use. Randy's site
is a fantastic resource for beginners and experienced
programmers alike.

Don't take things too personally and enjoy the group.

Jan Hyde (VB MVP)

-- 
Uphill: Oral medication for adults (Stan Kegel) 
[Abolish the TV License - http://www.tvlicensing.biz/]


Relevant Pages

  • Re: What is/is not considered to be good OO programming
    ... > get a twelve business class project working in almost any environment. ... you have an efficient development environment. ... > reply to any more of your posts. ...
    (comp.lang.php)
  • Re: The country I was raised in
    ... I did say had he told the truth it could have been a good learning experience for the teacher as well as the other children to learn that not everyone goes to church. ... It's called sarcasm. ... because it turned into a whole 'nother argument about how his parents were to blame.... ... Now, if I, or anyone else, am reading your posts wrong, and you were just posting to hear the keyboard rattle and didn't mean any of these things, please clarify what you were saying and I'll leave you to it. ...
    (sci.med.transcription)
  • Re: Sudo: local root compromise with krb5 enabled
    ... My program respects the $ALLOW_ROOT_COMPROMISE environment ... You may think root compromises are bad, ... when one's security software has an "API" consisting of hundreds ... but not documented in the API documentation! ...
    (Bugtraq)
  • Re: recursive folders?
    ... My own library functions use both FSO and the ... >API, depending on how important the speed of the function is. ... >work in a controlled environment where I can quickly restore WSR. ...
    (microsoft.public.vb.general.discussion)
  • Re: Goodbye uk.rec.cycling; Helllo U.R.C.moderated
    ... acceptance or test servers, so the ability of a user to see for ... This may be because in your environment your users ... from end to end for many people - there are many posts demonstrating that. ... Ultimately if a user feels the need for the crutch of a test message before ...
    (uk.rec.cycling)