I am working on a program and it calls for input validation for the text that the user enters into the text box. It does not want negative numbers or strings (i.e. "abcd...").
I understand how to do the negative numbers part of the validation but not the string part of the validation.
Here is what I have so far. I thought the IsNumeric funtion would work on it but I have a run-time error in and when I enter a letter (such as ABC) it doesnt do anything.
Also Does anyone know how to round numbers to just two decimal places. I am using the data entered in the textbox with some variables and then displaying the answer in a label, but when the math is complete I get 9.099990999 as an output and I just want it to be 9.09
Thanks ahead of time for the help!
I understand how to do the negative numbers part of the validation but not the string part of the validation.
Here is what I have so far. I thought the IsNumeric funtion would work on it but I have a run-time error in and when I enter a letter (such as ABC) it doesnt do anything.
Code:
Dim distance As Long
'Gets the distance for medium
If IsNumeric(txtDistance.Text) Then
distance = Val(txtDistance.Text)
'Validate text to make sure no negatives number or strings where
'entered into the text box
If distance < 0 Then
MessageBox.Show("Please enter positive number for " & _
"the distance for your selected medium.", "Text Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
End If
End If
Also Does anyone know how to round numbers to just two decimal places. I am using the data entered in the textbox with some variables and then displaying the answer in a label, but when the math is complete I get 9.099990999 as an output and I just want it to be 9.09
Thanks ahead of time for the help!