Highlighted
Alex_Castro Respected Contributor.
Respected Contributor.
187 views

Masking Controls in Windows Form

Jump to solution

I am trying to display a label control with the date field 07/23/19 but I instead get 72319 (I do not want the use to pick a date just simply to display a date to the user).  I believe there is a way to mask controls in windows form in order to get date fields and phone numbers but I am unsure as to the specific syntax for achieving this. I have attempted the following:

 

set lbl-DATE::Text type MaskedTextBox::

 

This line of code, however, is either incorrect or incomplete.

0 Likes
1 Solution

Accepted Solutions
Austin1 Honored Contributor.
Honored Contributor.

Re: Masking Controls in Windows Form

Jump to solution

In this case, assuming your date field is just a traditional COBOL numeric field, I would just move it to a traditional date edit word type field and then set the label to that, for example:

01  MyDate                pic 9(06).

01  EditedMyDate          pic Z9/99/99.

    Move MyDate                to EditedMyDate.

    set lbl-DATE::Text         to EditedMyDate.

 

0 Likes
4 Replies
Austin1 Honored Contributor.
Honored Contributor.

Re: Masking Controls in Windows Form

Jump to solution

In this case, assuming your date field is just a traditional COBOL numeric field, I would just move it to a traditional date edit word type field and then set the label to that, for example:

01  MyDate                pic 9(06).

01  EditedMyDate          pic Z9/99/99.

    Move MyDate                to EditedMyDate.

    set lbl-DATE::Text         to EditedMyDate.

 

0 Likes
Alex_Castro Respected Contributor.
Respected Contributor.

Re: Masking Controls in Windows Form

Jump to solution
That worked, thank you! It was an easy solution and I had something similar but I thought one could mask controls int he control property or with 'MaskTextBox' command. But this works for now.
0 Likes
Micro Focus Expert
Micro Focus Expert

Re: Masking Controls in Windows Form

Jump to solution

MaskedTextBox is not a command, it is a control itself just like the Label control or a textbox control that can be selected from the Toolbox and dragged onto the screen. You can use this control and assign format strings to it for data entry or you can set it to ReadOnly and use it to format display data instead of using a Label.

The .NET DateTime valuetype also contains many different ways to format a date or time field.
See docs here:

There are several other methods available for formatting strings or numeric fields such as String.Format or Convert.

Here is an example of a Winform that has two maskedTextBox controls and two Label controls on it.
This example assumes that you are using standard COBOL PIC X fields to store your date and phone number data.

       01 my-date          pic x(8)  value "01021999".
       01 my-phone         pic x(10) value "8001112222".

        *> Using maskedTextBox with format 00/00/0000
           set maskedTextBox1::Text to my-date
        *> Using maskedTextBox with format (999) 000-0000
           set maskedTextBox2::Text to my-phone

        *> Using DateTime valuetype to set a label to a formatted date string
           declare enUS as type CultureInfo = new type CultureInfo("en-US")
           declare datetoformat = type DateTime::ParseExact(my-date, "mmddyyyy", enUS, type DateTimeStyles::None)
           set label1::Text to datetoformat::ToShortDateString
        *> Using String.Format method to format a phone number from a string
           set label2::Text to type String::Format("{0:(###) ###-####}", type Int64::Parse(my-phone))

 

 

Alex_Castro Respected Contributor.
Respected Contributor.

Re: Masking Controls in Windows Form

Jump to solution
Thank you! This is a much better way to mask fields!
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.