Private Sub text1_KeyPress(Index As Integer, KeyAscii As Integer) '我要在此事件中处理text1只接受0-9的键值,其它的过滤,该怎么写? if keyascii>=48 and keyascii<=57 '操作 endifEnd Sub
什么操作都不须要,只要过滤之后在text1上显示就行了。
Private Sub text1_KeyPress(Index As Integer, KeyAscii As Integer) if keyascii>=48 and keyascii<=57 '操作 else keyascii=0 endif End Sub操作只可输入数字及有效键的函数: Private Sub text1_KeyPress(Index As Integer, KeyAscii As Integer) keyascii=IsNum(Keyascii) End SubPublic Function IsNum(Expression As Integer) As Integer Select Case Expression Case 8, 46, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57 IsNum = Expression Case Else IsNum = 0 End Select End Function
If KeyAscii = vbKeyTab Or KeyAscii = vbKeyBack Then Exit Sub Dim a As String a = Chr(KeyAscii) If IsNumeric(a) = False Then KeyAscii = 0
'我要在此事件中处理text1只接受0-9的键值,其它的过滤,该怎么写?
if keyascii>=48 and keyascii<=57
'操作
endifEnd Sub
if keyascii>=48 and keyascii<=57
'操作
else
keyascii=0
endif
End Sub操作只可输入数字及有效键的函数:
Private Sub text1_KeyPress(Index As Integer, KeyAscii As Integer)
keyascii=IsNum(Keyascii)
End SubPublic Function IsNum(Expression As Integer) As Integer
Select Case Expression
Case 8, 46, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57
IsNum = Expression
Case Else
IsNum = 0
End Select
End Function
Dim a As String
a = Chr(KeyAscii)
If IsNumeric(a) = False Then KeyAscii = 0