Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone to do so.
The attached control is a modified TextBox does all that for you and it also has these additional properties:
- This is a Boolean property that determines if the number can have decimals or not
- This is a Boolean property that determines if the number can be negative or not
- This property allows the user to set the maximum allowable number of decimals
- This property allows the user to set the minimum acceptable value
- This property allows the user to set the maximum acceptable value
- This property determines which character ("." or ",") is used as the decimal separator
- This is a Boolean property that determines if at least one digit must preceed the decimal separator
is a link to the code which once compiled will add the NumberBox to the list of available project Components. You can add the control to a project by going to Project|Components and checking NumberBox. I would have liked to be able to attach the code here in a zip file, but the zip contains file types that Experts Excgange won't allow to be uploaded even though they are all perfectly valid VB file types.
Note that this control is fairly widely used (for a 3rd-party OCX) on another site and has gone through 16 versions with associated version testing so it is thoroughly tested. Having said that if you do find a problem please let me know the details and I'll attempt to correct it.
If you find that this article has been helpful, please click the “thumb’s up” button below. Doing so lets me know what is valuable for EE members and provides direction for future articles. It also provides me with positive feedback in the form of a few points. Thanks!