Suppression of Leading Zeroes in Numeric Mask Text Box Control

I have a masked text box control on my windows form which I want to use in order to display a SSN to the user. I chose a predefined mask description in the properties windows and it looks as follows: 000-00-0000.

When I move a value that has leading zeroes to my mask text box, however, it drops the leading zeroes. For example, if I move a value of '000001234' to the mask text box, it displays it as follows:  123-4_-____. 

I works well if there are no leading zeroes. If I move the value '123456789'  to the mask text box for example, it displays it correctly as follows: '123-45-6789'. 

  • Verified Answer

    This is expected behavior if you are moving an actual numeric field or value to the Text property but it should work correctly if this is converted to a string first.

    set MaskedTextBox1::Text to "000123456"    *> this will work
    set MaskedTextBox1::Text to 000123456       *> this will have the zeroes stripped as it is an integer

    Does this work for you?

    If you are using a numeric field like pic 9(9) you could move it to a pic x(9) field and then use this as your sending field.

  • Your suggestion worked! I created a temporary field and declared it as follows:

    01 TMP-SSN PIC X(09)

    I then moved my numeric field into the the temporary field and sent the temporary field to the text box as follows:




    Thanks for your help!