Solved

Help w/combo boxes

Posted on 1999-01-29
8
182 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
8 Comments
 

Expert Comment

by:dudemann
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Expert Comment

by:spardog
Comment Utility
what ever item in the combo box is selected will be stored as  cbobox.text
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:Peanuthead
Comment Utility
I need to use indexes because each name causes other info to appear upon clicking it.
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
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 50 total points
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now