943,752 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 16521
  • VB.NET RSS
Jul 18th, 2004
0

combo box help

Expand Post »
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

VB.NET Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
salating is offline Offline
2 posts
since Jul 2004
Jul 19th, 2004
0

Re: combo box help

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:

VB.NET Syntax (Toggle Plain Text)
  1. If cmbAge.SelectedIndex = -1 Then
  2. MessageBox.Show("Please Select Your Age", "Error")
  3. cmbAge.Focus()
  4. Exit Sub
  5. Else
  6. ...
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Eyrestes is offline Offline
3 posts
since Jul 2004
Jul 20th, 2004
0

Re: combo box help

yea i actually did it like this

VB.NET Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
salating is offline Offline
2 posts
since Jul 2004
Jul 20th, 2004
0

Re: combo box help

That's a more elegant solution. Well done.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Eyrestes is offline Offline
3 posts
since Jul 2004

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Checking if a file is in Writing/Saving mode
Next Thread in VB.NET Forum Timeline: AutoCAD API and VB.NET





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC