Good Evening everyone,

I'm having a bit of an issue with my code. I know what the issue is but I'm not sure the best way of going around it.

It's a school project and I'm not allowed to use Return, Throw etc in it.


I was trying to use a do while loop to validation and force a user to re-enter correct data. I get all the correct error boxes and messages, but the loop keeps forcing the message boxes before the error can be corrected.

Im sure I could change it around and just use IF Statements but is that the best way ?

Here is the main code

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Const dblTenCents As Double = 0.1
Const dblThirteenCents As Double = 0.13
Dim intMin As Integer
Dim intMax As Integer
Dim MinTotalPrice As Double
Dim MaxTotalPrice As Double
Dim blnGood As Boolean
blnGood = False

Try



Do

lblTotalCalc.Text = String.Empty

If cboTitle.Text = "" Then
MessageBox.Show("Please Enter Title, Example Mr. \ Mrs.")
lblTotalCalc.Text = String.Empty
'Return
'End If

ElseIf txtFirstName.Text = "" Then
MessageBox.Show("Please Enter First Name")
lblTotalCalc.Text = String.Empty
'Return
'End If

ElseIf txtLastName.Text = "" Then
MessageBox.Show("Please Enter Last Name")
lblTotalCalc.Text = String.Empty
'Return
'End If

ElseIf Not Integer.TryParse(cboMin.Text, intMin) Or String.IsNullOrWhiteSpace(cboMin.Text) Then
MessageBox.Show("Please Enter or select a Whole Number Greater than 0")
lblTotalCalc.Text = String.Empty
'Return

ElseIf intMin < 0 Then
MessageBox.Show("Please Enter or select a Whole Number Greater than 0 for Min")
lblTotalCalc.Text = String.Empty
'Return

ElseIf intMin > 300 Then
MessageBox.Show("Minimum Value cannot be greater than 300 , Please Re-Enter")
lblTotalCalc.Text = String.Empty
'Return

'Making sure that there is a valid number
ElseIf Not Integer.TryParse(cboMax.Text, intMax) Or String.IsNullOrWhiteSpace(cboMax.Text) Then
MessageBox.Show("Please Enter or select a whole Number Greater than 0 for Max")
lblTotalCalc.Text = String.Empty
'Return

'Making sure that the number is not greater than 300
ElseIf intMax > 300 Then
MessageBox.Show("Maximum Valuse cannot be greater than 300, Please Re-Enter")
lblTotalCalc.Text = String.Empty
'Return

'Making sure that the Minimun is not greater than the Max.
ElseIf intMin > intMax Then
MessageBox.Show("Mininum Number cannot be greater than the Maximum, Please Re-Enter")
lblTotalCalc.Text = String.Empty
'Return

Else
blnGood = True

End If
'Program will loop until the data is true and flip the flag to true for calculations
Loop Until blnGood = True


Catch ex As Exception

End Try