|
Question : Escape while loop, then re-run while loop
|
|
I am in the process of learning Visual Basic (for work), and I am creating a sample application to test my knowledge so far... It's a simple application with 5 combo boxes that the user can select certain features of their computer, and then this information will be displayed back to the user.
The problem: I am trying to add some error checking into the application, such that if a combo box is empty it will prompt the user, and then give them a chance to try again...all combo boxes must be filled out before the pop up window will display with the computer info they entered.
What it's currently doing: it's stuck in the while loop after it hits the comboFilled = False... What I think I need to do: I need to break out of the while loop to get them a chance to re-enter info in the combo box. They would then click on "Submit" again to fire off the while loop error check.
This is what I have so far... check runs after they click "Submit":
' ////////////////////////////////////////////////////////////// ' On Click of the "submit" button check if combo boxes are blank ' \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Dim comboFilled As Boolean
While comboFilled = False If (Me.newProcType.SelectedItem = Nothing) Then MessageBox.Show("You did not select a Proc type.") comboFilled = False Else myNewBox.Proc = Me.newProcType.SelectedItem.ToString() comboFilled = True End If
If (Me.newProcSpeed.SelectedItem = Nothing) Then MessageBox.Show("You did not select a Proc speed.") comboFilled = False Else myNewBox.ProcSpeed = Me.newProcSpeed.SelectedItem.ToString() comboFilled = True End If
If (Me.newMemory.SelectedItem = Nothing) Then MessageBox.Show("You did not select any Memory.") comboFilled = False Else myNewBox.Memory = Me.newMemory.SelectedItem.ToString() comboFilled = True End If
If (Me.newHardDrive.SelectedItem = Nothing) Then MessageBox.Show("You did not select a Hard drive.") comboFilled = False Else myNewBox.HardDrive = Me.newHardDrive.SelectedItem.ToString() comboFilled = True End If
If (Me.newMonitor.SelectedItem = Nothing) Then MessageBox.Show("You did not select a Monitor.") comboFilled = False Else myNewBox.Monitor = Me.newMonitor.SelectedItem.ToString() comboFilled = True End If
End While
' //////////////////////////////////////////////////////////////////////// ' If the combo boxes are filled then continue...which pops up a message with the computer info. ' \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
MessageBox.Show(myNewBox.Display())
|
|
Answer : Escape while loop, then re-run while loop
|
|
If the code you posted is in a Button click event handler then just place a Return command after the display of the error, like this
If (Me.newProcType.SelectedItem = Nothing) Then MessageBox.Show("You did not select a Proc type.") Return Else myNewBox.Proc = Me.newProcType.SelectedItem.ToString() comboFilled = True End If
If (Me.newProcSpeed.SelectedItem = Nothing) Then MessageBox.Show("You did not select a Proc speed.") Return Else myNewBox.ProcSpeed = Me.newProcSpeed.SelectedItem.ToString() comboFilled = True End If
and do the same for the others.
|
|
|
|