请问高手,如何实现在输入时只能敲数字键和退格键!!

阿狸Jay(塘主) 2004-01-01 10:47:15
有Backspce相对应的ASCII码吗?请问高手,如何实现在输入时只能敲数字键和退格键!!
...全文
94 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
northwolves 2004-01-02
  • 打赏
  • 举报
回复

Private Sub Form_Load()
Me.KeyPreview = True
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If Not InStr("1234567890" & Chr(8), Chr(KeyAscii)) > 0 Then KeyAscii = 0
End Sub
kmzs 2004-01-02
  • 打赏
  • 举报
回复
来晚了
cymwllbggyje 2004-01-02
  • 打赏
  • 举报
回复
Private Sub Text1_KeyPress(KeyAscii As Integer)
If Not (KeyAscii = 8 Or (KeyAscii >= 48 And KeyAscii <= 57)) Then KeyAscii = 0
End Sub
cso 2004-01-02
  • 打赏
  • 举报
回复
Private Sub text1_KeyPress(KeyAscii As Integer)
If ((KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> 9) Then
KeyAscii = 0
End If
End Sub
Acsdnmember 2004-01-02
  • 打赏
  • 举报
回复
The same to kmzs
Richard2001 2004-01-02
  • 打赏
  • 举报
回复
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case Asc("-") '不允许负数
KeyAscii = 0
Case 8 '无变化,退格键不屏蔽
Case Asc(" ") '不允许空格
KeyAscii = 0
Case Asc(".") '46 '不允许小数点
KeyAscii = 0
Case Is < Asc(0) '48
If KeyAscii <> vbKeyReturn Then KeyAscii = 0
Case Is > Asc(9) '57
KeyAscii = 0
End Select

Exit Sub
End Sub

FSoft 2004-01-01
  • 打赏
  • 举报
回复
Private Sub Text1_KeyPress(KeyAscii As Integer)
If IsNumeric(Chr(KeyAscii)) = False And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub

7,763

社区成员

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

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