[RESOLVED] Combobox Question about String and Integer
i have this code
Quote:
Private Sub Form_Load()
Carrier.AddItem "MB496LE/A"
Carrier.ItemData(Carrier.NewIndex) = 80
End Sub
and here is my command button
Quote:
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?
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.
Re: Combobox Question about String and Integer
Sir LaVolpe can you give an example code please?
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.
Re: Combobox Question about String and Integer
thanks so much sir LaVolpe
it worked!
i have exactly what i want
thankyou so much