Help w/combo boxes

I am designing a database type program that the user will be able to add a name to a combobox, then when they want to acess the data under that name, they click on the name in the combobox.  I know this is quite simple...BUT...i need to know how to get the data from the combobox without using about 500 if..then loops(up to 500 items can be stored).  So instead of typing- if combo1.index = 1 then...
                      if combo1.index = 2 then...
etc.
how would i have the program like KNOW what the currently selected index value is.  I have defined a type that has the item's name, price, date purchased, and additional info.  These are all filled into different text boxes and then when u click a button, it clears these boxes and adds the name of the item to the combobox.  thats basically how the program works, just to clarify it for ya.  thx
PeanutheadAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
VBKidConnect With a Mentor Commented:
This has probably been said a few times before but here is an idea:

You caould save each person's info in a text file called "people.txt" with a different person's name on a different line.  Then use this code to store each one of the lines in a dynamic array:

Dim Info() As String
Redim Info(1)

Sub Form_Load
     Open "people.txt" For Input As #1
     Do Until Eof(1)
          B = B + 1
          ReDim Info(1 To B)
          Line Input 1, Info(B)
     Loop
     Close
End Sub

Then you can populate the list box with the names in the same order as you typed in the descriptions.  Then use this sub to change the text box to say the description of the person you click on:

Sub Combo1_Change
     Text1.Text = Info(Combo1.Index)
End Sub
0
 
dudemannCommented:
If I understand your question correctly, you want to get the index and value of an item selected in a combobox.  I printed these in the immediate window.  

' This one prints the value of the item selected in the combobox
?frmAdhocReports.cboYear.List(frmAdhocReports.cboYear.ListIndex)
1999

' This one prints the value of index for the item selected in the combobox.
?frmAdhocReports.cboYear.ListIndex
 3

Hopefully this is what you are looking for!
0
 
rayfordCommented:
This is done differently in say Access than in Visual Basic.  If you are using standard Visual Basic then the previous two comments are on track to get you where you are going so try working with those.  

If you are in Access there is a whole other set of information you will want as well.  One thing I will throw out again is that you should always consider not binding your controls directly to your data tables unless you are certain that will provide some improvement to your methods or processing.  Typically programs like Access will warn you when for instance you've populated a bound field with an invalid value.  VB will blow up with an error instead - teaching us that ON ERROR handling in VB has to be a constant consideration.  I've almost always hidden my bound controls off screen and used unbound controls to interface with the user as display and get inputs.  This is not the Access area but if you are indeed working in Access by some chance let me know I'll rant onward.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
PeanutheadAuthor Commented:
I dont think that u quite understood what im asking...
What i need to know is:
How do i make a combobox that the user can add names to, and these names can then be reselected and the information can be shown about them.  The trouble im having is that i dont want to have 500 if..then statements for each index value of the combobox when they select a name.  So what i need is a way for the program to recognize the current index value being shown.  Ask about anything that needs clarification.
0
 
spardogCommented:
what ever item in the combo box is selected will be stored as  cbobox.text
0
 
PeanutheadAuthor Commented:
I need to use indexes because each name causes other info to appear upon clicking it.
0
 
Éric MoreauSenior .Net ConsultantCommented:
Is it possible to keep a collection or an array that will contains extra information that your combo won't. Keeping the same index will easier your work for retreiving from the other structure!
0
 
dudemannCommented:
You could use a command button or an item in your combobox entitled "Add Name".  Whenever you fire the event, you could use an InputBox that gets the name, then add the name to the database, get the cboName.count, additem the new name, and the cboName.count is prob the index of that new name.  Then you could do a cboName.ListIndex = cboName.count.  You could also, after saving the new record, do a select on that table to re populate your cboBox.


0
All Courses

From novice to tech pro — start learning today.