展开全部
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 48 To 57
Case 97 To 100
Case Else
'If (KeyAscii < 48 Or KeyAscii > 57) Or (KeyAscii >= 97 Or KeyAscii <= 100) Then
'Else
KeyAscii = 0
MsgBox "输入了非法字符"
'End If
End Select
End Sub
已验证,运行正常
Select Case KeyAscii
Case 48 To 57
Case 97 To 100
Case Else
'If (KeyAscii < 48 Or KeyAscii > 57) Or (KeyAscii >= 97 Or KeyAscii <= 100) Then
'Else
KeyAscii = 0
MsgBox "输入了非法字符"
'End If
End Select
End Sub
已验证,运行正常
追问
如果只能输入a,b,c,d,呢?
追答
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 97 To 100
Case Else
KeyAscii = 0
MsgBox "输入了非法字符"
End Select
End Sub
展开全部
Private sub text1_Keypresss(Keyascii as integer)
if keyascii<48 or keyascii>57 then
keyascii=0
msgbox("必须输入的是数字")
end if
end sub
if keyascii<48 or keyascii>57 then
keyascii=0
msgbox("必须输入的是数字")
end if
end sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If (KeyCode > Asc(9) Or KeyCode < Asc(0)) And KeyCode <> 8 Then
MsgBox "不允许按其他键"
SendKeys "{backspace}"
End If
End Sub
这样么?
If (KeyCode > Asc(9) Or KeyCode < Asc(0)) And KeyCode <> 8 Then
MsgBox "不允许按其他键"
SendKeys "{backspace}"
End If
End Sub
这样么?
追问
调试后SendKeys "{backspace}"这句是黄色,如果是只能输入a,b,c,d 怎么写代码
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询