这个是限制输入非数字类型的Private Function CheckInput(KeyAscii As Integer) If KeyAscii = 8 Or KeyAscii = 9 Or (KeyAscii > 47 And KeyAscii < 58) Then Else KeyAscii = 0 End If CheckInput = KeyAscii End Function Private Sub Text1_KeyPress(KeyAscii As Integer) KeyAscii = CheckInput(KeyAscii) End Sub
text1.selstart=0
text1.sellength=len(text1.text)
msgbox "请输入数字"
end if
'不是数字
elseend if
msgbox "你输入的不是数字!"
exit sub
end if
可以放在LostFocus或按确定按钮时提示.
If KeyAscii = 8 Or KeyAscii = 9 Or (KeyAscii > 47 And KeyAscii < 58) Then
Else
KeyAscii = 0
End If
CheckInput = KeyAscii
End Function
Private Sub Text1_KeyPress(KeyAscii As Integer)
KeyAscii = CheckInput(KeyAscii)
End Sub
=================================
放在keypress中不够,因为复制粘贴该事件不会发生
我是最慢的.呵呵..