Limit numbers in a lable

Posted on 2007-08-07
Last Modified: 2013-11-05
Hi guys i am sure this one is going to be a easy one for you all,
i am using buttons and enter numbers in to a label and i am want to limit and about of numbers that are allowed in the caption, i am wanting it for date so when they are typing in 15 April 1912, it will only allow then to type in two number in the leading caption and 4 in the last one, these are all different captions
Question by:awolarczuk
    LVL 20

    Expert Comment

    Use MaxLength

    So you could put label.MaxLength = 2

    This would limit it to two characters.

    Author Comment

    where about do i put the label.maxlength my lable is call day so do i go in the code day.caption = day.caption + 1 and put it in there somewhere
    LVL 20

    Expert Comment

    You can go on the form itself and set the property of MaxLength for each label or in your code when you load the form you can set the property in code for example:

    day.MaxLength = 2
    year.MaxLength = 4
    LVL 12

    Accepted Solution

    A label control doesn't have the "MaxLength" property, but only TextBox controls.

    >> i am wanting it for date so when they are typing in 15 April 1912, it will only allow then to type in two number in the leading caption and 4 in the last one

    How could you do that in a Label control, which does not directly accept user input, but rather from code as in setting the Caption property?

    In the case of using the MaxLength property, try a TextBox control.

    For more flexibility in "formatting" the date, use a more sophisticated control such as the DatePicker, which is available in the Microsoft Windows Common Controls 2.0 (MSCOMCT2.OCX).
    LVL 20

    Assisted Solution


    Sorry,  Yes I was using the term label as had been used by awolarczuk but had assumed Text box control since there was user input.  I should have been more clear.  Thanks for clarifying.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Suggested Solutions

    Title # Comments Views Activity
    Help with my python script 6 135
    ShiftLeft challenge 21 50
    Use Multiple Forms 4 30
    sumDigits  challenge 7 40
    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    This article will show, step by step, how to integrate R code into a R Sweave document
    This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
    The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now