-
Jun 9th, 2010, 02:02 PM
#1
Thread Starter
Member
[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.
-
Jun 9th, 2010, 02:07 PM
#2
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.
-
Jun 9th, 2010, 02:09 PM
#3
Thread Starter
Member
Re: Combobox Question about String and Integer
Sir LaVolpe can you give an example code please?
-
Jun 9th, 2010, 02:15 PM
#4
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.
-
Jun 9th, 2010, 02:22 PM
#5
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|