Microsoft KB Archive/150186

= BUG: Setting Focus to a Masked Edit Control Causes Error =

Article ID: 150186

Article Last Modified on 3/14/2005

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q150186



SYMPTOMS
Setting focus to a Masked Edit control, which previously did not have the focus, triggers the ValidationError event of the control. If the Masked Edit control loses the focus, the ValidationError event is fired again.

The InValidText parameter received in the event represents the invalid characters that the user tried to type. When the event is fired erroneously because the control receives focus, the InValidText parameter is one character long, and becomes the same as the PromptChar. The example below avoids warning the user if a control is used to set focus to the control: Private Sub MaskEdBox1_ValidationError(InvalidText As String, _  StartPosition As Integer) If Mid$(InvalidText, StartPosition + 1, 1) <> MaskEdBox1.PromptChar Then MsgBox "You are typing in the wrong stuff" End If  End Sub



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Problem
 Start a new project in Visual Basic. Form1 is created by default. Place a Masked Edit control and a Command button on to Form1. Switch to the Properties window for the Masked Edit control, and change the Mask to #.  In the Click event for the Command button, place the following code: Private Sub Command1_Click

MaskEdBox1.SetFocus

End Sub   In the ValidationError event for the Masked Edit control, enter the following code: Private Sub MaskEdBox1_ValidationError(InvalidText As String, _

StartPosition As Integer)

MsgBox "You are typing in the wrong stuff"

End Sub  Run the project by clicking F5. Click on the Command button and the Msgbox indicates that the ValidationError event was incorrectly fired.

To correct the problem with the workaround earlier, change the code in the ValidationError event to: Private Sub MaskEdBox1_ValidationError(InvalidText As String, _  StartPosition As Integer) If Mid$(InvalidText, StartPosition + 1, 1) <> MaskEdBox1.PromptChar Then MsgBox "You are typing in the wrong stuff" End If  End Sub

Additional query words: kbVBp400bug kbVBp500bug kbVBp600bug kbVBp kbdsd kbDSupport kbControl

Keywords: kbbug kbpending kbcontrol KB150186

-

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

© Microsoft Corporation. All rights reserved.