Using a library to do form validation can save lots of your development time. j Query Form validation library is the most popular validation library.My code is as follows: I tried it on my own before without the CDbl() part, and I got the same result. Textboxes are not meant to be used for numeric entries. If you use them in that way they require a whole bunch of additional code to keep them error free and even then there are ways to left to get it wrong that you can't ever effectively preclude.I found the above online, and tried it, but I got the same result. Reviews: "dunfiddlin likes his Data Tables" - jmcilhinney Please be aware that whilst I will read private messages (one day! I am trying to limit a textbox to a certain range of numbers. Hide Selection = True End If End Sub Private Sub Text Box1_Validated(sender As Object, e As Event Args) Handles Text Box1. Text Length 2007-2016 Why is my data not saved to my database? " Videos: VB | C# VBForums Database Development FAQ My Code Bank Submissions: VB | C# My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control Beginner Tutorials: VB | C# | SQL And again, use the Numeric Up Down control.I want someone to be able to type in a number from 0-20. If someone types 21 or higher, it changes it to 20, If someone types 1, and then puts a - in front of it, it will change it to 0. Show("Please enter a number in the range 0.0 to 20.0 inclusive.", "Invalid Input", Message Box Buttons. Error) 'Don't let the user leave the control until the contents is valid. It doesn't require any additional validation, you can set the minimum and maximum values, and you don't have to worry about errors like this.The problem comes when they delete the number in the box, or put a - with no number (to write -1). The error is caused by attempting to convert an empty string to a numeric value which clearly can't be done.I get this error: A first chance exception of type 'System. Visual and Conversion from string "" to type 'Double' is not valid. You would get the same error if you typed in a non-numeric character which you don't seem to have considered as a possibility at all.Reviews: "dunfiddlin likes his Data Tables" - jmcilhinney Please be aware that whilst I will read private messages (one day!
Most notably, the Numeric Up Down shows a fixed number of decimal places. " Videos: VB | C# VBForums Database Development FAQ My Code Bank Submissions: VB | C# My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control Beginner Tutorials: VB | C# | SQL I don't need it to be a double.Given that the OP is using Double rather than Integer, it is quite possible that they want to allow an arbitrary number of decimal places, in which case the NUD is definitely not appropriate. That was just a bit of code I found that was like mine. It is only for using whole numbers, so I do not need decimal places.I will look into the Numeric Up Down control and see if this will work for me.Thank you all very much for the super fast replies.
I know there is something I am missing, I am just not sure what to add to make it work. ) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!That may well be a solution but it's certainly not guaranteed, as many seem to think.