• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 403
  • Last Modified:

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


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

Open in new window

0
johnnyjonathan
Asked:
johnnyjonathan
  • 2
  • 2
  • 2
  • +1
1 Solution
 
gplanaCommented:

Just put a select case statement inside the other, so you can create the 9 combinations:
Private Sub Command1_Click()
End
End Sub

Private Sub Command2_Click()
    Select Case Combo1.ListIndex
    Case 1
       Select Case Combo2.ListIndex
       Case 1
         MsgBox "USA+GREEN"
       Case 2
         MsgBox "USA+BLACK"
       Case 3
         MsgBox "USA+BLUE"
       Case Else
         MsgBox "Please choose first"
       End Select

    Case 2
       Select Case Combo2.ListIndex
       Case 1
         MsgBox "Russia+GREEN"
       Case 2
         MsgBox "Russia+BLACK"
       Case 3
         MsgBox "Russia+BLUE"
       Case Else
         MsgBox "Please choose first"
       End Select
    Case 3
       Select Case Combo2.ListIndex
       Case 1
         MsgBox "Italy+GREEN"
       Case 2
         MsgBox "Italy+BLACK"
       Case 3
         MsgBox "Italy+BLUE"
       Case Else
         MsgBox "Please choose first"
       End Select
   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

Open in new window

0
 
GrahamSkanRetiredCommented:
You could concatenate the text values of the two combos. However this is an unusual way of working. Why not just put all (9 in this example) choices int one combo?

Select Case Combo1.Text & Combo2.Text
      Case  "USAGREEN"
          'Action 1
      Case   "USABLACK"
           'Action 2
'...

Open in new window

0
 
johnnyjonathanAuthor Commented:
@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?
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
gplanaCommented:
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).
0
 
GrahamSkanRetiredCommented:
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:


Private Sub Command2_Click()
      MsgBox "You selected " & Combo1.Text & " from Combo1 and " & vbCrLf & Combo2.Text & " from Combo2."
End Sub

Open in new window

0
 
jruheCommented:
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

Open in new window

0
 
johnnyjonathanAuthor Commented:
Worked out great (after i figured what you mean) thanks a lot!
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now