<

Go Premium for a chance to win a PS4. Enter to Win

x

A Textbox ActiveX Control That Limits Input to Numbers

Published on
15,597 Points
5,397 Views
2 Endorsements
Last Modified:
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Join & Write a Comment

This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month