<

A Textbox ActiveX Control That Limits Input to Numbers

Published on
15,715 Points
5,515 Views
2 Endorsements
Last Modified:
Approved
Martin Liss
Over 40 years of programming experience. Expand my "Full Biography" to see links to some articles I've written.
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:

CanHaveDecimals - This is a Boolean property that determines if the number can have decimals or not

CanBeNegative - This is a Boolean property that determines if the number can be negative or not

MaxDecimals - This property allows the user to set the maximum allowable number of decimals

MinValue - This property allows the user to set the minimum acceptable value

MaxValue - This property allows the user to set the maximum acceptable value

DecimalSeparator - This property determines which character ("." or ",") is used as the decimal separator

RequireLeadingDigit - This is a Boolean property that determines if at least one digit must preceed the decimal separator

Here 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!
2
Comment
Author:Martin Liss
0 Comments

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Join & Write a Comment

Suggested Articles

This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month