编程目的:在一个文本框内只能输入数字,输入错了可以用"{BackSpace}"删除。文本框的属性没有改动,但运行时按一次退格键却删了两个数字,办什么呢?????
请高手帮忙看看,附代码如下:
Private Sub Form_Load()
Text1.Text = ""
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii > 47 And KeyAscii < 59) Or KeyAscii = 46 Then
If (Len(Text1.Text) < 1 And KeyAscii = 48) Then
KeyAscii = 0
Text1.Text = ""
End If
ElseIf (Len(Text1.Text) > 0 And KeyAscii = 8) Then
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1) '用'SendKeys"{BackSpace}"也是一样
Text1.SelStart = Len(Text1.Text)
Else
MsgBox "请输入数字。", 0, "错误" 'vbDefaultButton1 'If Len(Text1.Text) > 0 Then Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
' Text1.SelStart = Len(Text1.Text)
KeyAscii = 0
Text1.SelStart = Len(Text1.Text)
End If
End Sub