thankins Posted September 24, 2003 Posted September 24, 2003 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. 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! Quote
thankins Posted September 24, 2003 Author Posted September 24, 2003 Oh yea Option Strict is set to ON as part of the program prerequiste so I can't have any implicit conversions! :confused: Quote
JABE Posted September 25, 2003 Posted September 25, 2003 How about using a NumericUpDown control instead? Quote
thankins Posted September 25, 2003 Author Posted September 25, 2003 hmm What do you mean, I am not knowing what the NumericUpDown function is. Quote
JABE Posted September 25, 2003 Posted September 25, 2003 If you're writing a Windows Forms app, you can use the NumericUpDown control instead of the Textbox control. That way, you don't have to code much (if at all) to validate the numeric input because it's automatically done for you. Look for the NumericUpDown control in the Toolbox. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.