Results 1 to 4 of 4

Thread: [Resolved] combo box help

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    10

    [Resolved] combo box help

    i have four combo boxes in my form, each combo box has 2 or 3 selections

    i need to check each combo box for a selection, if nothing is selected i need to have a error message come up in a message box

    each selection in the combobox is woth different points so i am using a counter and when the user click the button it shows the total points in a message box
    Code:
    If cmbAge.SelectedIndex = -1 Then
         MessageBox.Show("Please Select Your Age", "Error")
         cmbAge.Focus()
         If cmbAge.SelectedIndex = 0 Then
              intPtsCnt = intPtsCnt + 1
         ElseIf cmbAge.SelectedIndex = 1 Then
              intPtsCnt = intPtsCnt + 2
         ElseIf cmbAge.SelectedIndex = 2 Then
              intPtsCnt = intPtsCnt + 3
         End If
    End If
    i have one of these for each combo box

    when i run the program and click the button all 4 error message boxes show up then it shows the total points, i want it to go through each combo box one at a time
    Last edited by salating; Jul 18th, 2004 at 06:05 PM.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Try using Exit Sub method at the end of each If and ElseIf :
    VB Code:
    1. If Me.ComboBox1.SelectedIndex = -1 Then
    2.             MessageBox.Show("Please Select Item from Cbox1 ", "Error")
    3.             Exit Sub
    4.  
    5.         ElseIf Me.ComboBox2.SelectedIndex = -1 Then
    6.             MessageBox.Show("Please Select Item from Cbox2", "Error")
    7.             Exit Sub
    8.  
    9.         ElseIf Me.ComboBox3.SelectedIndex = -1 Then
    10.             MessageBox.Show("Please Select Item from Cbox3", "Error")
    11.             Exit Sub
    12.  
    13.         End If

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    10
    thanks, i got it to work

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by salating
    thanks, i got it to work
    Can you edit the thread title and add [Resolved] tag .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width