I am creating an application and on one of the forms
I have created 3 combo boxes with various items inside one is all of the states ca, alabama,etc and another has seasons  winter,summer,spring,etc and another has regions north south ,east etc
I have various outcomes for each selected (example if california and north and east are selected then lblanswer.caption = "whatever"
But I cant figure out how to code this easily as there are so many different outcomes.
my question is: Is there an easy way ? and how do I code it
Thanx
Who is Participating?

x

Commented:
There's no way to get away from the fact that there are so many outcomes.  However, there is a fairly easy way to map the selections to text "answers":

Assuming that each combination results in different answers (or that this is the usual case), you'll need to use a multi-dimensional array.

The array must have as many dimensions as the number of item types, so in your case, that's 3 dimensions (state, season, region).

Now the hard part.  You've got to fill the array somehow.  There's no escaping this work.  It just has to be done.

Once you've got the array filled, the rest is easy.  Just use the .listindex property of the combos to figure out what member of the array to use.  I've pasted all the code you need for this below.  Start a new project and add three combos and a label to Form1.  Name the combos cmbState, cmbRegion, and cmbSeason.  Name the label lblAnswer.  Then paste the code, below into the form.
=============================
Option Explicit

Const StateMax = 50
Const RegionMax = 6
Const SeasonMax = 4

1 To RegionMax, _
1 To SeasonMax _
) As String

Dim i, j, k As Long

For i = 1 To StateMax
For j = 1 To RegionMax
For k = 1 To SeasonMax
Answers(i, j, k) = "Answer for (" + CStr(i) + "," + CStr(j) + "," + CStr(k) + ")"
Next k
Next j
Next i

'Fill combo boxes and set to default selection
For i = 1 To StateMax
Next i
cmbState.ListIndex = 0

For i = 1 To RegionMax
Next i
cmbRegion.ListIndex = 0

For i = 1 To SeasonMax
Next i
cmbSeason.ListIndex = 0

End Sub

Private Sub cmbRegion_Click()
End Sub

Private Sub cmbSeason_Click()
End Sub

Private Sub cmbState_Click()
End Sub

'Handle indexing errors gracefully, since
'at start, some listindexes will be invalid.
On Error Resume Next

'ListIndex is zero-based!  Could have let arrays default
'to zero-based.  Whatever you prefer!
cmbRegion.ListIndex + 1, _
cmbSeason.ListIndex + 1)
End Sub

=======================

Good luck!

----------------------
Mike Thomas
----------------------

0

Author Commented:
thank you for the responce.I am new to vb im in my 6th month at the local college
ive done 2 other arrays and Im a little lost still
is there any way you could give me step by step as I cannot look at code and completely
decipher it yet.
or make a sample prog
thank you
d.ray@mindspring.com
0

Author Commented:
Ive made the program but dont know where to put the answers in the code could you make an example with a few answers "answer1","2",etc
0

Commented:
The place where it says "Fill Answers Array" is where you'd put code to put the answers in the array.  It would be better to put this into a Sub or Function, since it will become LARGE.

The bummer is that you have x*y*z entries in the array to fill, where x is states, y is regions, and z is seasons.  Depending upon how many regions you actually have (let's assume 6), this turns out to be 1200 entries in the array.  A real pain.  Anyway, the idea is you have to fill the array values "by hand".

For example, assume that the first state is Alabama:

-------------------

Private Sub FillArray()
'I don't know what your answers are supposed to be, so I'm
'faking it here.
.
.
.

End Sub

-------------------

It occurs to me that your states must be related to the regions in some way???

It seems weird to have 3 interdependent dropdown lists where two of them sort of overlap in definition.  It seems as though if you select "Southeast", for example, that you should only see states such as Alabama, Louisiana, Florida, Georgia, etc.  Is there supposed to be a relationship like this?  If so, there's more work to do in some ways and less in others.  The reason I ask this question is why would someone select something like Florida, Northwest, and Winter?  What purpose does the selection of Florida and Northwest serve?  I guess I'm saying that I need to know more about your problem to solve it effectively at this point.

later...
0

Commented:
When thinking about arrays, think of something physical to help.  For example, a one dimensional array is like a row of boxes, each with a number.  You can put something in each box and then give someone instructions on how to get a particular item by telling them what number to go to.  So you could hand them a piece of paper saying boxes(6), and they'd go to the 6th box and take out whatever's there.

Multidimensional arrays just add another dimension (obviously).  So you'd have a bunch of boxes laid out in a square shape on the floor and number them as to rows and columns.  With this arrangement you'd say boxes(1, 3), which would tell the person to get something out of row one, column three.

A three dimensional array would maybe be like a row of veritcal storage units full of boxes (take the square of boxes from above and turn it up on its side to be vertical).  Then you'd say boxes(3,1,2) to instruct a person to go to the third storage unit, 1st shelf, third column (or box).

It'd be easier to draw a picture, but this is the idea.

For your particular example, let's say the storage units each represent a State, the shelves represent Regions, and the boxes, numbered left to right, represent Seasons.  Can you picture this?  This is how the array works.

I hope this helps, rather than confuses.

later...
0

Author Commented:
It is for a fly fishing application.
select state
select region (north ,south ,east,west)
select season winter,summer,spring

and shows you the bug hatchings from your selection at season times and regions
So you will know which flies to use at proper regions and times
Also I added the other code and nothing?
still cant figure it out, how to code the answers
0

Commented:
That code was just a demonstration of something you might do!! :-)  YOU need to do all the coding for populating the array YOURSELF.  I mean, that's where the usefulness of the program comes in, it's kind of like the program's "intelligence".  I can't do that for you.

So is "region" the region of the state?  Or is it a region of the country?  If it is region of the country, then it's reasonable to expect the user to pick that FIRST, since then you can limit the state box to only states in the selected region.  If it's region of the state, then I've given all the logic you need.  You just have to do the hard work of filling in the array.

I'll try to explain it again.  Give each state a number.  This number is the number you'll use for the index of information for the state.  Give each region a number.  This is used for region indexes.  Give each season a number.  This is used for season indexes.  If you give Alabama a "1", South a "1", and Winter a "3", then the way to SET the answer for "South Alabama in Winter" is:

I've given you all of the code you need and have explained arrays at length.  I don't know what else to give you at this point.  If you have specific questions, go ahead and ask them, and I'll try to answer.

Sorry if I seem grumpy, but it's late and I'm tired :-)

later...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.