Private Sub textbox1_KeyPress(KeyAscii As Integer) If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0 End If End Sub
Private Sub textbox1_KeyPress(KeyAscii As Integer) If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then KeyAscii = 0 End If End Sub
转贴: Public Function sffunLimitNumber(ByVal IntVal As Integer) As Integer '-------------------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
Private Sub Text1_KeyPress(KeyAscii As Integer) Dim Strvalid As String Strvalid = "0123456789" If KeyAscii > 26 Then If InStr(Strvalid, Chr(KeyAscii)) = 0 Then KeyAscii = 0 End If End IfEnd Sub
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
End If
End Sub
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub
Public Function sffunLimitNumber(ByVal IntVal As Integer) As Integer
'-------------------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
Dim Strvalid As String
Strvalid = "0123456789"
If KeyAscii > 26 Then
If InStr(Strvalid, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End IfEnd Sub