Textbox Value check

Arg81

Well-known member
Joined
Mar 11, 2005
Messages
949
Location
Midlands, UK
Programming Experience
1-3
I've set my textboxes so they accept numeric values only.

I want to make sure that the user can't enter a value above 100 - is the best way to check this to do something along the lines of;

VB.NET:
If me.textbox1.text >100 Then
   MessageBox.Show("Please enter a value less than or equal to 100")
End If

Thanks,
 
actually doesn't look too bad - I was worried it would look awful as I've got about 10 on my form now.

Problem I have encountered - when I was using textboxes, I used _Validating and _Validation to check the entered value, and also if the textbox is blank the user must enter a value before moving onto the next textbox.

When using NumericUpDown control, there is a default value of 0 - if the user accidently presses tab to move onto the next control, the validation kicks in and rejects the "row", as the value is 0.

Anyway I can set it so the NUD displays nothing, or is it a case of editing my validation code to bypass 0? (which may cause issues, as 0 can be within the range accepted, it depends on the values of some other textboxes)
 
you could set the default being "1" with a Minimum of "0" and a max of "100"

so the row wont be rejected, but the data would be incorrect if the user doesn't change the value
 
That still won't work because the _Validating events will pick up on the 1 if the user still accidently presses Tab before entering the value.

I've actually found a way around this. Even though it doesn't appear in the IntelliSense, you can set the .Text property of a NumericUpDown.

All I've done is set

me.nud1.text = nothing
me.nud2.text = nothing

etc etc, at Form_Load, and this then loads "blank" numericUpDowns, which then work with my validation rules :D

Thanks for the initial tips, think I finally got what I needed!
 
Back
Top