johnnyjonathan
asked on
How to correlate VB commands
Hello,
Apologizes upfront for maybe not describing my problem\question clearly but i just started learning visual basic (using Visual Basic 6.0) and i managed to create a simple .exe file with 3 sub menus and a NEXT button, i know how to make each sub menu perform an action once i press on the NEXT button, but my question is how can i correlate these menus? for example:
Menu 1 has 3 choices:
USA
Russia
Italy
Menu 2 has 3 choices:
Green
Black
Blue
how can i make it so if i choose Russia + Green i get one action, but Russia + Blue will give me another action (or any other kind of a combination)
The simple code i made is written below
Apologizes upfront for maybe not describing my problem\question clearly but i just started learning visual basic (using Visual Basic 6.0) and i managed to create a simple .exe file with 3 sub menus and a NEXT button, i know how to make each sub menu perform an action once i press on the NEXT button, but my question is how can i correlate these menus? for example:
Menu 1 has 3 choices:
USA
Russia
Italy
Menu 2 has 3 choices:
Green
Black
Blue
how can i make it so if i choose Russia + Green i get one action, but Russia + Blue will give me another action (or any other kind of a combination)
The simple code i made is written below
Private Sub Combo1_Change()
End Sub
Private Sub Combo2_Change()
End Sub
Private Sub Combo3_Change()
End Sub
Private Sub Command1_Click()
End
End Sub
Private Sub Command2_Click()
Select Case Combo1.ListIndex
Case 0
MsgBox "Please choose first"
Case 1
MsgBox "USA"
Case 2
MsgBox "RUSSIA"
Case 3
MsgBox "ITALY"
Case Else
MsgBox "Please choose first"
End Select
Select Case Combo2.ListIndex
Case 0
MsgBox "Please choose first"
Case 1
MsgBox "GREEN"
Case 2
MsgBox "BLACK"
Case 3
MsgBox "BLUE"
Case Else
MsgBox "Please choose first"
End Select
Private Sub Form_Load()
Dim oMap As String
Combo1.AddItem "<Select >"
Combo1.AddItem "USA"
Combo1.AddItem "RUSSIA"
Combo1.AddItem "ITALY"
Combo2.AddItem "<Select>"
Combo2.AddItem "GREEN"
Combo2.AddItem "BLACK"
Combo2.AddItem "BLUE"
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@gplana, thanks but the idea isn't to create just 9 lists, i only gave examples the actual list is longer hence i wanted to do the correlations
@GrahamSkan, I'm sorry but i couldn't exactly understand from the example you wrote how can i take a selected action from combo1 and combo2 ?
where does it state which action i took?
@GrahamSkan, I'm sorry but i couldn't exactly understand from the example you wrote how can i take a selected action from combo1 and combo2 ?
where does it state which action i took?
My solution doesn't creat 9 lists, but just to make an example in how you can make a different action for every combination of the 3 values of both of your lists (so 3x3 = 9 combinations).
I left you to fill in the actions that you want to take in the commented out sample lines
However, if you want display a message box, you can do it in one line:
However, if you want display a message box, you can do it in one line:
Private Sub Command2_Click()
MsgBox "You selected " & Combo1.Text & " from Combo1 and " & vbCrLf & Combo2.Text & " from Combo2."
End Sub
Is this what you're looking for Johnny? I took what gplana and GrahamSkan had and put them together in your original code. Obviously, you can put the same code in Combo1_Change, but you may want to avoid the "Case Else" part in that combo box.
Private Sub Combo2_Change()
Select Case Combo1.Text & Combo2.Text
Case "USAGREEN"
'Action 1
Case "USABLACK"
'Action 2
...
Case Else
MsgBox "Please choose both a country and a color"
End Select
End Sub
ASKER
Worked out great (after i figured what you mean) thanks a lot!
Open in new window