bigboywasim
Member
- Joined
- Sep 29, 2006
- Messages
- 18
- Programming Experience
- Beginner
VB.NET:
Dim blnErrorFlag As Boolean
Dim UserError1 As InvalidCastException
Dim UserError2 As ArithmeticException
Try
If CDec(txtCarSalesPrice.Text) > 100000 Then
MsgBox("Car Sales Price Exceeds 100000. Enter Smaller Number", MsgBoxStyle.Critical)
txtCarSalesPrice.BackColor = Color.Red
blnErrorFlag = True
End If
If CDec(txtTradeInAllowance.Text) > 50000 Then
MsgBox("Trade In Allowence Exceeds 50000. Enter Smaller Number", MsgBoxStyle.Critical)
txtTradeInAllowance.BackColor = Color.Red
blnErrorFlag = True
End If
Catch UserError1
MsgBox("Enter Only Numbers")
Catch UserError2
MsgBox("Overflow Please Enter Smaller Value")
End Try
I have a problem with two things. The first one is that if I enter a value only in one textbox and hit the calculate button the program crashes. I get exited out of the form. I think it has something to do with the CDec since the complier has nothing to convert. I do not know how to fix this.
The second problem I have is that I do not know how to code to change the background of the two textboxes to red when UserError1 or UserError2 happens. Please someone help me with this.