如何让该文本框只接收文字,其余输入报错。我知道用if语句判断,我想知道具体的代码。

summern 2003-10-25 09:18:45
如何让该文本框只接收文字,其余输入报错。我知道用if语句判断,我想知道具体的代码。
...全文
72 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
itlive 2003-10-25
  • 打赏
  • 举报
回复
不好意思上边那段没写完就发出去了补上
private sub key_press(keyascii as integer)
if keyascii<>8 then
If not (KeyAscii >= 33 And KeyAscii <= 47) Or (KeyAscii >= 58 And KeyAscii <= 65) Or KeyAscii >= 91 And KeyAscii <= 96) Or (KeyAscii >= 123 And KeyAscii <= 126) then

keyascii=0
end if
end if


end sub
itlive 2003-10-25
  • 打赏
  • 举报
回复
private sub key_press(keyascii)






end sub
Dennis618 2003-10-25
  • 打赏
  • 举报
回复
Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii >= 48 And KeyAscii <= 57) And KeyAscii <> 88 And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub
输入数字的话不显示。
8是"退格键" 88是"删除键"
yoki 2003-10-25
  • 打赏
  • 举报
回复
Private Sub Text1_KeyPress(KeyAscii As Integer)
'允许汉字、字符、数字及汉字中的字符
If (KeyAscii >= 33 And KeyAscii <= 47) Or _
(KeyAscii >= 58 And KeyAscii <= 65) Or _
(KeyAscii >= 91 And KeyAscii <= 96) Or _
(KeyAscii >= 123 And KeyAscii <= 126) Then MsgBox "aa"
Me.Caption = KeyAscii
End Sub
射天狼 2003-10-25
  • 打赏
  • 举报
回复
Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then KeyAscii = 0
End Sub
taosihai1only 2003-10-25
  • 打赏
  • 举报
回复
Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then
KeyAscii = 0
msgbox "error!"
endif
End Sub

7,789

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧