combo box help

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jul 2004
Posts: 2
Reputation: salating is an unknown quantity at this point 
Solved Threads: 0
salating salating is offline Offline
Newbie Poster

combo box help

 
0
  #1
Jul 18th, 2004
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

here is my code

  1. Private Sub btnAssessment_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAssessment.Click
  2. Dim intPtsCnt As Integer
  3.  
  4. If cmbAge.SelectedIndex = -1 Then
  5. MessageBox.Show("Please Select Your Age", "Error")
  6. cmbAge.Focus()
  7. Else
  8. If cmbAge.SelectedIndex = 0 Then
  9. intPtsCnt = intPtsCnt + 1
  10. ElseIf cmbAge.SelectedIndex = 1 Then
  11. intPtsCnt = intPtsCnt + 2
  12. ElseIf cmbAge.SelectedIndex = 2 Then
  13. intPtsCnt = intPtsCnt + 3
  14. End If
  15. End If
  16.  
  17.  
  18. If cmbSmoke.SelectedIndex = -1 Then
  19. MessageBox.Show("Please Select", "Error")
  20. cmbSmoke.Focus()
  21. Else
  22. If cmbSmoke.SelectedIndex = 0 Then
  23. intPtsCnt = intPtsCnt + 4
  24. ElseIf cmbSmoke.SelectedIndex = 1 Then
  25. End If
  26. End If
  27.  
  28. If cmbBP.SelectedIndex = -1 Then
  29. MessageBox.Show("Please Select", "Error")
  30. cmbBP.Focus()
  31. Else
  32. If cmbBP.SelectedIndex = 0 Then
  33. intPtsCnt = intPtsCnt + 2
  34. ElseIf cmbBP.SelectedIndex = 1 Then
  35. End If
  36. End If
  37.  
  38. If cmbDiet.SelectedIndex = -1 Then
  39. MessageBox.Show("Please Select", "Error")
  40. cmbDiet.Focus()
  41. Else
  42. If cmbDiet.SelectedIndex = 0 Then
  43. intPtsCnt = intPtsCnt + 1
  44. ElseIf cmbDiet.SelectedIndex = 1 Then
  45. End If
  46. End If
  47.  
  48. MessageBox.Show(Convert.ToString(intPtsCnt), "Total")
  49.  
  50. End Sub

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
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 3
Reputation: Eyrestes is an unknown quantity at this point 
Solved Threads: 1
Eyrestes's Avatar
Eyrestes Eyrestes is offline Offline
Newbie Poster

Re: combo box help

 
0
  #2
Jul 19th, 2004
Hi,

If I am understanding you correctly, then all you need to do is add an Exit Sub after the Focus() in each check for -1.

An example:

  1. If cmbAge.SelectedIndex = -1 Then
  2. MessageBox.Show("Please Select Your Age", "Error")
  3. cmbAge.Focus()
  4. Exit Sub
  5. Else
  6. ...
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 2
Reputation: salating is an unknown quantity at this point 
Solved Threads: 0
salating salating is offline Offline
Newbie Poster

Re: combo box help

 
0
  #3
Jul 20th, 2004
yea i actually did it like this

  1. If cmbAge.SelectedIndex = -1 Then
  2. MessageBox.Show("Please Select Your Age", "No Selection")
  3. cmbAge.Focus()
  4. ElseIf cmbSmoking.SelectedIndex = -1 Then
  5. MessageBox.Show("Please Select Smoker or Nonsmoker", "No Selection")
  6. cmbSmoking.Focus()
  7. ElseIf cmbBloodPressure.SelectedIndex = -1 Then
  8. MessageBox.Show("Please Select Your Blood Pressure", "No Selection")
  9. cmbBloodPressure.Focus()
  10. ElseIf cmbDiet.SelectedIndex = -1 Then
  11. MessageBox.Show("Please Select Your Diet Type", "No Selection")
  12. cmbDiet.Focus()
  13. End If
  14.  
  15. If cmbAge.SelectedIndex = 0 Then
  16. intCounter = intCounter + 1
  17. ElseIf cmbAge.SelectedIndex = 1 Then
  18. intCounter = intCounter + 2
  19. ElseIf cmbAge.SelectedIndex = 2 Then
  20. intCounter = intCounter + 3
  21. End If

it works both ways though
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 3
Reputation: Eyrestes is an unknown quantity at this point 
Solved Threads: 1
Eyrestes's Avatar
Eyrestes Eyrestes is offline Offline
Newbie Poster

Re: combo box help

 
0
  #4
Jul 20th, 2004
That's a more elegant solution. Well done.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC