Masking Controls in Windows Form

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.

  • Verified Answer

    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.

     

  • 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.
  • 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))

     

     

  • Thank you! This is a much better way to mask fields!