Private Sub Text1_KeyPress(KeyAscii As Integer)
KeyAscii = mytest(KeyAscii)
End Sub
Private Function mytest(KeyAscii As Integer) As Integer
Dim s As String
s = "0123456789." + Chr(8) + Chr(13) '定义允许输入的字符
Dim inputs As String
inputs = Chr(KeyAscii) '当前输入的字符
If InStr(1, s, inputs) = 0 Then '如果当前输入的字符没有包含在字符串s中,则过滤输入
mytest = 0
Exit Function
End If
mytest = KeyAscii
End Function
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 = IntVal