Microsoft KB Archive/99873

= BUG: MaskedEdit MaxLength Reset to 64 When Mask=&quot;&quot; =

Article ID: 99873

Article Last Modified on 10/30/2003

-

APPLIES TO


 * Microsoft Visual Basic 2.0 Professional Edition
 * Microsoft Visual Basic 3.0 Professional Edition

-



This article was previously published under Q99873



SYMPTOMS
When the Mask property of the MaskedEdit custom control is set to two quotation marks (&quot;&quot;), 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 = &quot;&quot; maskededit1.Text = &quot;&quot; '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 &quot;&quot; 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
 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. Add three Command buttons (Command1, Command2, and Command3) to Form1.  Add the following code to your program in the appropriate places: Sub Command1_Click Debug.Print &quot;MaskedEdit1.maxlength&quot;, maskededit1.MaxLength Debug.Print &quot;Text length&quot;, Len(maskededit1.Text) End Sub

Sub Command2_Click maskededit1.Mask = &quot;&quot; maskededit1.Text = &quot;&quot; End Sub

Sub Command3_Click Debug.Print &quot;MaxLength set to 10&quot; maskededit1.MaxLength = 10 End Sub  From the Run menu, choose start (ALT, R, S), or press F5. From the Window menu, choose debug (ALT, W, D) or press CTRL+B. The Debug Window will be displayed. Click Command1. You will see the current Maxlength value of 64 and the current text length of 0 displayed in the Debug Window.</li> 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.</li> 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.</li> Click Command2. This sets the mask property to &quot;&quot;, and clears the text in the MaskedEdit1 control.</li> 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.</li></ol>

Additional query words: buglist2.00 buglist3.00 2.00 3.00

Keywords: kbbug KB99873

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.