FIX: KeyPress Event Code Does Not Reset Value of KeystrokeID: Q183473
|
In Visual Basic, the KeyPress event can be used to validate keystrokes and prevent invalid characters from being entered in controls. The KeyAscii value can be evaluated for valid characters and reset to 0 (zero) to remove invalid characters. This method does not work in the controls for the Windows CE Toolkit for Visual Basic 5.0 (VBCE). Modifying the KeyAscii value has no affect on the character entered.
The KeyAscii value used by the control is not affected by changes made to its value in KeyPress event procedure code.
The following are two ways to work around this problem:
Private Sub Text1_LostFocus()
Dim sText, i, iChar
sText = Text1.Text
For i = 1 To Len(sText)
iChar = Asc(Mid(sText, i, 1))
If ((iChar < 48) Or (iChar > 57)) Then
MsgBox "Only digits allowed!"
Text1.SetFocus
Exit For
End If
Next
End Sub
Microsoft has confirmed this to be a problem in the Microsoft products listed
at the beginning of this article.
This problem was corrected in Windows CE Toolkit for Visual Basic 6.00.
Books Online for Microsoft Windows CE Toolkit for Visual Basic 5.0.
Additional query words: vbce wce vbce5 vbce6
Keywords : kbToolkit kbVBp kbVBp500bug kbVBp600fix kbWinCE kbWinCE100 kbGrpVB
Version : WINDOWS:1.0
Platform : WINDOWS
Issue type : kbbug
Last Reviewed: March 3, 1999