Saturday, September 27, 2008

Error Checking with isNumeric

Dim distance As Decimal = 0
Dim gallonsused As Decimal = 0
Dim mpg As Decimal = 0
If IsNumeric(Textgas.Text) = True And IsNumeric(Textmiles.Text) = True Then distance = Textmiles.Text
gallonsused = Textgas.Text
mpg = distance / gallonsused
Math.Round(mpg, 2)

mpgdisplay.Text = (mpg & " is your miles per gallon (mpg)")
Dim alertvariable As String = "Alert you are a gas guzzler!!!"
If mpg < 10 Then
alertlabel.Text = alertvariable
End If
If gallonsused > 50 Then
lblgasused.Text = ("you are using too much gas")
Else
MsgBox("You messed up. Gotta enter numbers")
End If
Else
MsgBox("Enter numbers")
Textmiles.Text = ""
Textgas.Text = ""
End If

No comments: