Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Help w/combo boxes

Posted on 1999-01-29
8
Medium Priority
?
190 Views
Last Modified: 2010-05-03
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
0
Comment
Question by:Peanuthead
[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
8 Comments
 

Expert Comment

by:dudemann
ID: 1471210
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
 
LVL 1

Expert Comment

by:rayford
ID: 1471211
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
 

Author Comment

by:Peanuthead
ID: 1471212
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Expert Comment

by:spardog
ID: 1471213
what ever item in the combo box is selected will be stored as  cbobox.text
0
 

Author Comment

by:Peanuthead
ID: 1471214
I need to use indexes because each name causes other info to appear upon clicking it.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 1471215
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
 

Accepted Solution

by:
VBKid earned 100 total points
ID: 1471216
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
 

Expert Comment

by:dudemann
ID: 1471217
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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

730 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