<

Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x

A Textbox ActiveX Control That Limits Input to Numbers

Published on
15,514 Points
5,314 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
0 Comments

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Join & Write a Comment

The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month