Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

refer to selection in combo box 1

Status
Not open for further replies.

sf123

Programmer
Oct 9, 2002
30
US
I filled up possible selections in a combo box by looping through contents of an array. I want the value of what they selected by the index of the array. Eg: if user selects red, I want to always refer to that as 1. if user selects orange, I want to always refer to that as 2 etc. How do you refer to the value? I know in java you can do .value but in vb when I did the name of my comboBox.value, it just set the initial value of combo box to that number.

sf
 

Give this a try...

[tt]
Option Explicit

Private Sub Form_Load()

Dim S As String, MyArray() As String, I As Integer

S = "Red Orange Yellow Blue Green"

MyArray = Split(S, " ")

For I = LBound(MyArray) To UBound(MyArray)

'combo1.AddItem "Item As String",Optional Index As Integer
Combo1.AddItem MyArray(I), I

Next I

End Sub

Private Sub Combo1_Click()

MsgBox "Color = " & Combo1.Text & " Index = " & Combo1.ListIndex + 1

End Sub

[/tt]

Note: Since array's are normally Base 0 I added + 1 to the listindex value.

I hope this helps, good luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top