Microsoft
Software
Hardware
Network
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.SelectedIt
em = Nothing) Then
MessageBox.Show("You did not select a Proc type.")
comboFilled = False
Else
myNewBox.Proc = Me.newProcType.SelectedIte
m.ToString
()
comboFilled = True
End If
If (Me.newProcSpeed.SelectedI
tem = Nothing) Then
MessageBox.Show("You did not select a Proc speed.")
comboFilled = False
Else
myNewBox.ProcSpeed = Me.newProcSpeed.SelectedIt
em.ToStrin
g()
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.SelectedI
tem = Nothing) Then
MessageBox.Show("You did not select a Hard drive.")
comboFilled = False
Else
myNewBox.HardDrive = Me.newHardDrive.SelectedIt
em.ToStrin
g()
comboFilled = True
End If
If (Me.newMonitor.SelectedIte
m = 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.D
isplay())
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.SelectedIt
em = Nothing) Then
MessageBox.Show("You did not select a Proc type.")
Return
Else
myNewBox.Proc = Me.newProcType.SelectedIte
m.ToString
()
comboFilled = True
End If
If (Me.newProcSpeed.SelectedI
tem = Nothing) Then
MessageBox.Show("You did not select a Proc speed.")
Return
Else
myNewBox.ProcSpeed = Me.newProcSpeed.SelectedIt
em.ToStrin
g()
comboFilled = True
End If
and do the same for the others.
Random Solutions
How to resolve the SQL error: "ORDER BY items must appear in the select list if the statement contains a UNION, INTERSECT or EXCEPT operator"?
How to configure FastCGI activity timeout for php-cgi.exe, Windows7, x64
NetworkStream.DataAvailabl<wbr />e returns false
Hijacked
C# equivalent of javascript's location.replace() function?
Converting Lotus .MK4 files to Excel
Domain Password policy did not apply on workstation
Importing Fixed Assets
Browser CSS Alignment
Any free DBF viewer software?