请VB高手帮我解释下下面这段代码?

来源:百度知道 编辑:UC知道 时间:2024/06/15 03:37:43
Private Sub txtDate_KeyPress(KeyAscii As Integer)
If KeyAscii >= 48 And KeyAscii <= 57 Then
ElseIf KeyAscii = 8 Then
ElseIf KeyAscii = Asc("-") Then
Else
KeyAscii = 0
End If
End Sub
这段代码是不是统计字数的?能解释下每行的意思吗? 谢谢

这段代码的功能是在文本框txtDate只允许输入数值和 - 号
还有可以退格删除字符,
这段代码的功能还不完善

Private Sub txtDate_KeyPress(KeyAscii As Integer)
If KeyAscii >= 48 And KeyAscii <= 57 Then '输入数值怎通过
ElseIf KeyAscii = 8 Then '退格键也通过
ElseIf KeyAscii = Asc("-") Then '可以输入- 号
Else
KeyAscii = 0 '如果是别的键就取消
End If
End Sub

Private Sub txtDate_KeyPress(KeyAscii As Integer) 'txtDate控件监视键盘输入事件
If KeyAscii >= 48 And KeyAscii <= 57 Then '如果输入的是数字,则...
ElseIf KeyAscii = 8 Then '如果输入是符号,则...
ElseIf KeyAscii = Asc("-") Then '如果输入的是-,则...
Else '如果都不是
KeyAscii = 0 '就清空键盘缓冲区
End If '结果判断
End Sub

在文本框txtDate只允许输入数值和 - 号