Results 1 to 5 of 5

Thread: [RESOLVED] Combobox Question about String and Integer

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2007
    Location
    Brunei Darussalam
    Posts
    50

    Resolved [RESOLVED] Combobox Question about String and Integer

    i have this code

    Private Sub Form_Load()
    Carrier.AddItem "MB496LE/A"
    Carrier.ItemData(Carrier.NewIndex) = 80
    End Sub
    and here is my command button

    Private Sub cmdDetermine_Click()

    MsgBox "You have selected " & Carrier.List(Carrier.ListIndex) & "." & vbNewLine _
    & "It has " & Carrier.ItemData(Carrier.ListIndex) & " Number.", _
    vbInformation, _
    "Carrier"

    End Sub
    after the equal sign i can only put numbers,
    how can i make it if i want to put word instead of number?

    somebody please help me?
    Last edited by eyestrain; Jun 9th, 2010 at 02:08 PM.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Combobox Question about String and Integer

    You can't directly. What you can do is use an array, collection or another hidden listbox/comobbox and add strings to that. Then the .ItemData can reference the entry in that array/collection/box item. That's just one option, a little thought on the subject, and you can think of other similar options.

    Edited: Actually you can store string pointers, but I wouldn't go that route unless you are very comfortable with moving string data via pointers.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2007
    Location
    Brunei Darussalam
    Posts
    50

    Re: Combobox Question about String and Integer

    Sir LaVolpe can you give an example code please?

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Combobox Question about String and Integer

    Code:
     Dim myCol As Collection
    
    Private Sub Form_Load()
        Set myCol = New Collection
        Carrier.AddItem "MB496LE/A"
        myCol.Add "This would be the string related to MB496LE/A"
        Carrier.ItemData(Carrier.NewIndex) = myCol.Count
    End Sub 
    
    Private Sub cmdDetermine_Click()
    
    MsgBox "You have selected " & Carrier.List(Carrier.ListIndex) & "." & vbNewLine _
    & "Associated String: " & myCol.Item(Carrier.ItemData(Carrier.ListIndex)) , _
    vbInformation, "Carrier"
    
    End Sub
    This type of solution is easy but if you will be removing items from the combobox, then the index numbers in the collection change too when the associated items are removed. So keeping them in sync requires more effort.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Member
    Join Date
    Dec 2007
    Location
    Brunei Darussalam
    Posts
    50

    Re: Combobox Question about String and Integer

    thanks so much sir LaVolpe
    it worked!

    i have exactly what i want

    thankyou so much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width