BUG: MaskedEdit MaxLength Reset to 64 When Mask=""

Last reviewed: June 21, 1995
Article ID: Q99873
The information in this article applies to:

- Professional Edition of Microsoft Visual Basic for Windows,

  versions 2.0 and 3.0

SYMPTOMS

When the Mask property of the MaskedEdit custom control is set to two quotation marks (""), the MaxLength property is incorrectly reset to 64. However, the control continues to correctly limit input based on the original MaxLength setting, and you can change the value of MaxLength to establish a different maximum text limit for the control.

WORKAROUND

To work around the problem, store the MaxLength property before setting the Mask property of the MasedEdit custom control. Then reset the MaxLength setting after setting the Mask property.

For example, replace the code shown in the Command2_Click event procedure in step 3 of the More Information section below with this code:

   Sub Command2_Click ()
      Dim ml As Integer
      'Store the current MaxLength property value
      ml = maskededit1.MaxLength
      maskededit1.Mask = ""
      maskededit1.Text = ""
      'Restore the MaxLength property value since
      'it has incorrectly been reset to 64
      maskededit1.MaxLength = ml
   End Sub

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

If you set the mask property to "" at run time the MaxLength property is incorrectly set to 64, but the amount of text you can enter is still limited by the original MaxLength setting.

Steps to Reproduce Problem

  1. Start Visual Basic or from the File menu, choose New Project (ALT, F, N) if Visual Basic is already running. Form1 is created by default.

  2. Add three Command buttons (Command1, Command2, and Command3) to Form1.

  3. Add the following code to your program in the appropriate places:

       Sub Command1_Click ()
          Debug.Print "MaskedEdit1.maxlength", maskededit1.MaxLength
          Debug.Print "Text length", Len(maskededit1.Text)
       End Sub
    
       Sub Command2_Click ()
          maskededit1.Mask = ""
          maskededit1.Text = ""
       End Sub
    
       Sub Command3_Click ()
          Debug.Print "MaxLength set to 10"
          maskededit1.MaxLength = 10
       End Sub
    
    

  4. From the Run menu, choose start (ALT, R, S), or press F5.

  5. From the Window menu, choose debug (ALT, W, D) or press CTRL+B. The Debug Window will be displayed.

  6. Click Command1. You will see the current Maxlength value of 64 and the current text length of 0 displayed in the Debug Window.

  7. Click Command3 to set MaxLength to 10. This is verified in the Debug Window. Type text into the MaskedEdit1 control. Notice that you are allowed to enter a maximum of 10 characters.

  8. Click Command1. The Debug Window shows that Maxlength is set to 10. The current text length will reflect the number of characters you typed into the MaskedEdit1 Control.

  9. Click Command2. This sets the mask property to "", and clears the text in the MaskedEdit1 control.

  10. Click Command1 to see that the Maxlength property is now incorrectly

        set to 64. Type text into the MaskedEdit1 control, and note that you
        allowed to enter a maximum of 10 characters.
    


Additional reference words: buglist2.00 buglist3.00 2.00 3.00
KBCategory: kbprg kbbuglist
KBSubcategory: PrgCtrlsCus


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 21, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.