Private Sub Text3_KeyPress(KeyAscii As Integer)
If KeyAscii < vbKey0 Or KeyAscii > vbKey9 Then '不接受数字以外的字符
MsgBox "输入字符无效"
Text3 = Left(Text3, Len(Text3) - 1)
End If
End Sub
If KeyAscii < vbKey0 Or KeyAscii > vbKey9 Then '不接受数字以外的字符
MsgBox "输入字符无效"
Text3 = Left(Text3, Len(Text3) - 1)
End If
End Sub
0-->48
9__>57
MsgBox "输入字符无效"
KeyAscii = 0
End If
If KeyAscii < vbKey0 Or KeyAscii > vbKey9 Then '不接受数字以外的字符
MsgBox "输入字符无效"
KeyAscii = 0End If好像吧删除键都屏蔽掉了,不方便修改内容,怎样改一下使删除键有效??
'-------------------1-------------------
'目 的:只允许在文本框内输入数字、退格、删除及回车键
'输 入:ByVal IntVal As Integer,任意的键值
'被传递值:无
'返 回 值:过滤后的键值
'输 出:无
'注 解:
'用 法:在文本框的KeyPress事件中输入KeyAscii = sffunLimitNumber(KeyAscii)即可
'修 订 版:
'-------------------1-------------------
If (IntVal <> vbKeyDelete) _
And (IntVal <> vbKeyBack) _
And (IntVal <> 13) _
And (IntVal < 48 Or IntVal > 57) Then
IntVal = 0
End If
sffunLimitNumber = IntValEnd Function
汉字也一样,只允许ASCII的范围是0-255就是了!
On Error Resume Next'***********************************字段不为数值的有效性验证********************
If Chr(KeyAscii) = vbBack Or KeyAscii = 46 Then Exit Sub
If Not IsNumeric(Chr(KeyAscii)) Or Chr(KeyAscii) < 0 Then
KeyAscii = 0
MsgBox "数量必需是数值!请重新输入!!", vbOKOnly, "Stop!!"
End If
End Sub
chr(keyascii)=vbback or keyascii=46