?
Solved

VB6 - Combo Control/Drop Down Question

Posted on 2005-03-31
6
Medium Priority
?
4,717 Views
Last Modified: 2012-06-22
In HTML, if I want to display one thing, but get a different value I would do something like this:

<select name="combo">
<option value=1>John Doe</option>
<option value=2>Jane Smith</option>
<option value=3>Joe Blow</option>
</select>

How can I do the same thing (combo which assigns a value of 1 if John Doe is selected, etc) in VB6, figure using a combo control or maybe a list box?
0
Comment
Question by:Lee W, MVP
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 32

Accepted Solution

by:
Erick37 earned 2000 total points
ID: 13677560
You can use the ItemData property to store this info:

ItemData Property Example
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vb98/html/vbproitemdatax.asp
0
 
LVL 11

Expert Comment

by:bingie
ID: 13677562
Sure can, but it can only be integer data.

You can use the Combo1.ItemData(index as integer) property, when index is the index of the item

Add a combo box and paste the following (just select and item) to see how to do it:

Private Sub Combo1_Click()
 MsgBox Combo1.ItemData(Combo1.ListIndex)
End Sub

Private Sub Form_Load()
 Combo1.AddItem "first"
 Combo1.ItemData(0) = 1
 Combo1.AddItem "second"
 Combo1.ItemData(1) = 2
 Combo1.AddItem "third"
 Combo1.ItemData(2) = 3
End Sub
0
 
LVL 96

Author Comment

by:Lee W, MVP
ID: 13677581
I thought so... but the documentation I looked at didn't seem clear on this.  Thanks, I'll test things and let you both know.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 14

Expert Comment

by:Shiju Sasidharan
ID: 13678252
hi
u can also use NewIndex Property to get newly added entry
'===============================
Private Sub Form_Load()
Dim i
    For i = 1 To 10
        Combo1.AddItem "Item " & i
        Combo1.ItemData(Combo1.NewIndex) = i
    Next i
End Sub
'===============================

;-)
Shiju
0
 
LVL 96

Author Comment

by:Lee W, MVP
ID: 13722409
Ok, working on it again now (if I don't finish today, won't get back to it until Monday).  That said, how do I retrieve BOTH the index and the text data?
0
 
LVL 96

Author Comment

by:Lee W, MVP
ID: 13722924
Thanks folks - have to select Erick37 as the answer - The link he provided was REALLY helpful and he did post first.  
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question