| | |
combo box help
Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jul 2004
Posts: 2
Reputation:
Solved Threads: 0
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
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
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)
Private Sub btnAssessment_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAssessment.Click Dim intPtsCnt As Integer If cmbAge.SelectedIndex = -1 Then MessageBox.Show("Please Select Your Age", "Error") cmbAge.Focus() Else 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 If cmbSmoke.SelectedIndex = -1 Then MessageBox.Show("Please Select", "Error") cmbSmoke.Focus() Else If cmbSmoke.SelectedIndex = 0 Then intPtsCnt = intPtsCnt + 4 ElseIf cmbSmoke.SelectedIndex = 1 Then End If End If If cmbBP.SelectedIndex = -1 Then MessageBox.Show("Please Select", "Error") cmbBP.Focus() Else If cmbBP.SelectedIndex = 0 Then intPtsCnt = intPtsCnt + 2 ElseIf cmbBP.SelectedIndex = 1 Then End If End If If cmbDiet.SelectedIndex = -1 Then MessageBox.Show("Please Select", "Error") cmbDiet.Focus() Else If cmbDiet.SelectedIndex = 0 Then intPtsCnt = intPtsCnt + 1 ElseIf cmbDiet.SelectedIndex = 1 Then End If End If MessageBox.Show(Convert.ToString(intPtsCnt), "Total") 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
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:
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)
If cmbAge.SelectedIndex = -1 Then MessageBox.Show("Please Select Your Age", "Error") cmbAge.Focus() Exit Sub Else ...
•
•
Join Date: Jul 2004
Posts: 2
Reputation:
Solved Threads: 0
yea i actually did it like this
it works both ways though
VB.NET Syntax (Toggle Plain Text)
If cmbAge.SelectedIndex = -1 Then MessageBox.Show("Please Select Your Age", "No Selection") cmbAge.Focus() ElseIf cmbSmoking.SelectedIndex = -1 Then MessageBox.Show("Please Select Smoker or Nonsmoker", "No Selection") cmbSmoking.Focus() ElseIf cmbBloodPressure.SelectedIndex = -1 Then MessageBox.Show("Please Select Your Blood Pressure", "No Selection") cmbBloodPressure.Focus() ElseIf cmbDiet.SelectedIndex = -1 Then MessageBox.Show("Please Select Your Diet Type", "No Selection") cmbDiet.Focus() End If If cmbAge.SelectedIndex = 0 Then intCounter = intCounter + 1 ElseIf cmbAge.SelectedIndex = 1 Then intCounter = intCounter + 2 ElseIf cmbAge.SelectedIndex = 2 Then intCounter = intCounter + 3 End If
it works both ways though
![]() |
Similar Threads
- combo box (PHP)
- Want to use radio button or menu bar instead of combo box (Java)
- combo box (ASP)
- How do I limit text char in Combo box? (VB.NET)
Other Threads in the VB.NET Forum
- Previous Thread: Checking if a file is in Writing/Saving mode
- Next Thread: AutoCAD API and VB.NET
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2008 access add application arithmetic array assignment basic binary bing box button buttons click code combobox component connectionstring convert cpu data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees excel exists file-dialog firewall folder google hardcopy image images isnumericfuntioncall login math memory mobile module ms msaccess mssqlbackend mysql navigate net networking opacity output peertopeervideostreaming picturebox1 port print printpreview problemwithinstallation project record regex reports" reuse right-to-left save savedialog serial sqldatbase storedprocedure string temp text textbox timer toolbox updown useraccounts usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vbnet view vista visual visualbasic visualbasic.net visualstudio web wpf xml





