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!

Determine selected item: cmbo or listbox

Status
Not open for further replies.

Schrammie

Programmer
Dec 13, 1999
2
US
I'm trying to create an If...then statement.<br>
What I would like to occur is if user selects an item from the list, a label will display a number (ex: if user selects item &quot;Very good&quot;, then lblLabel1.Caption = 5).<br>
Somewhere along the way, I am not understanding how to write the code. I am assuming it has something to do with the index #. (if you can't tell, I'm brand new to programming, trying to teach myself)<br>
Anyone got a suggestion?<br>
<br>
Thanks in advance.
 
The listindex property of the listbox and combobox is a long which gives you the index of the selection. It starts a 0 and goes to number of items in list -1. another way to do it is to associate a value in the itemdata property for the newly added item and then retrieve that value.<br>
<br>
to add a value to the itemdata use<br>
<br>
list.itemdata(list.newindex) = value<br>
<br>
to retrive the itemdata property use<br>
<br>
value = list.itemdata(list.listindex)<br>
<br>
<br>
James :)
 
you can also use<br>
x=List1.text <br>
it will return just the text<br>
or x will equal &quot;Very good&quot; in your case.<br>
<br>
here is a code example<br>
<br>
Private Sub Form_Load()<br>
List1.AddItem &quot;Very Good&quot;<br>
List1.AddItem &quot;Normal&quot;<br>
List1.AddItem &quot;Bad&quot;<br>
End Sub<br>
<br>
Private Sub List1_Click()<br>
If List1.Text = &quot;Very Good&quot; Then<br>
' put your code here<br>
End If<br>
End Sub<br>
<br>
DougP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top