I am trying to validate two text boxes in VB 10 Express. The first validation (parts) is working as desired, and the form will not proceed to the next step until zero or a positve number is entered. The second validation (labor) is not working as I would like. If left blank or a negative number or text is entered, the message box displays "Labor must be zero or a positive number", but when you click ok, the remainder of the form executes. I would like to force the user to enter zero or a positive number before moving on. I can't figure out why the two validations are behaving differently. Any advice?
'Get the parts cost from user.
If Decimal.TryParse(txtParts.Text, decParts) Then
'Validate the parts costs.
If decParts >= 0 Then
'display parts
lblParts.Text = decParts.ToString("c")
'Get the labor cost from user
If Decimal.TryParse(txtLabor.Text, decLabor) Then
'Validate the labor cost.
If decLabor >= 0 Then
'add labor to the hidden service label
lblLabor.Text = decLabor.ToString("c")
Else
'Error: labor prices are missing or negative
MessageBox.Show("Labor must be 0 or a positive number.")
End If
Else
'Error: labor prices are missing or negative.
MessageBox.Show("Labor must be 0 or a positive number.")
End If
'Get the parts tax
decTax = decParts * decTAX_RATE
decServiceLabor = OilLube() + Flushes() + Misc() + decParts + decLabor
decTotal = decServiceLabor + decParts + decTax
lblServiceLabor.Text = decServiceLabor.ToString("c")
lblTax.Text = decTax.ToString("c")
lblTotal.Text = decTotal.ToString("c")
Else
'Error: parts prices are missing or negative
MessageBox.Show("Parts must be 0 or a positive number.")
End If
Else
'Error: parts prices are missing or negative.
MessageBox.Show("Parts must be 0 or a positive number.")
End If