ComboBox index

G

Guest

Hi,
I am new to VB,
I created a comboBox using VB and included 3 items in it
I created a command button and a label button.
I would like to display selection from comboBox into the label box when I
click on the command button.
I am using the following code but I keep getting the first value entered in
comboBox.
Does the index or ListIndex the one that gets updated with the value
selected from the combo box? I need to save that value to do some math with
it but before I do that I want to make sure that it is in fact the last
selection.

Private Sub Command1_Click()
Label1.Caption = Combo1.ItemData(Index)

End Sub
Private Sub Label1_Click()

End Sub


Thanks
 
B

Bob Phillips

Private Sub Command1_Click()
Label1.Caption = Combo1.Value
End Sub


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 
G

Guest

Hi bob
I tried this before and I get the following error:
"method or data member not found" and ".Value" is highlighted.
do I need to set something up in the comboBox properties first.
In the comboBox properties, where should I enter items, in
"List" Field or "ItemData" Field

Thanks
 
T

Tom Ogilvy

Private Sub Command1_Click()
With Combo1
Label1.Caption = .list(.ListIndex)
End With
End Sub

assuming that Combo1 is the name of your combobox.
 
G

Guest

Thanks Tom, this worked for me.
So what is the deal?
Label1.Caption = Combo1.Value
only works with excel visual basic? cause the above worked in excel vb but
not in vb6.0

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top