在对一个表格第三列,和第四列控制,只能小数,和整数,语句如下,
Private Sub gd_KeyPress(KeyAscii As Integer)
If gd.Col = 2 Or gd.Col = 3 Then
If KeyAscii < 48 Or KeyAscii > 57 Then '48=is0,57 is9
MsgBox gd.Col & KeyAscii
KeyAscii = 0
End If
End If
结果不理想,如果先输入一个数字,在输入字母也能输入。如:9kdsjjd也能输入。怎么解决这个问题,
我这个语句还不能对小数进行判断,请高手帮改正一下。多谢。
Private Sub gd_KeyPress(KeyAscii As Integer)
If gd.Col = 2 Or gd.Col = 3 Then
If KeyAscii < 48 Or KeyAscii > 57 Then '48=is0,57 is9
MsgBox gd.Col & KeyAscii
KeyAscii = 0
End If
End If
结果不理想,如果先输入一个数字,在输入字母也能输入。如:9kdsjjd也能输入。怎么解决这个问题,
我这个语句还不能对小数进行判断,请高手帮改正一下。多谢。
解决方案 »
- 请问个Propertychenged的问题
- 程序调用Excel,打包需打进哪些文件?
- 我的电脑忽然mmcontrol不能播放mp3了,有没有人知道为什么?
- 求教如何进行窗体事件过程相互调用?
- 请问我如何得知某个ocx的classid是多少,howdo!?thanks
- 谁有true dbgrid pro7.0的注册码或者是解密软件!先谢了
- 图片打印如何占满一张纸
- 高分请问: Recordset.Delete的问题
- help ,help,,
- 如何去除一个字符串的后四个字符?或者把除后几个字符之外的字符赋给另一个变量?
- 如何在VB中调用ORACLE的包?
- 谁有用TREEVIEW作的资源管理器################################################
Private Sub gd_KeyDown(KeyCode As Integer)
If gd.Col = 2 Or gd.Col = 3 Then
If KeyCode >= 48 and KeyAscii <= 57 Then '48=is0,57 is9
'MsgBox gd.Col & KeyAscii
'KeyAscii = 0
else
'MsgBox gd.Col & KeyAscii
'KeyAscii = 0
exit sub
End If
End If
结果不理想,如果先输入一个数字,在输入字母也能输入。如:9kdsjjd也能输入。怎么解决这个问题,
我这个语句还不能对小数进行判断,请高手帮改正一下。多谢。
Private Sub gd_KeyPress(KeyAscii As Integer)
If KeyAscii = 8 Then Exit Sub'箭头键
If KeyAscii < 48 Or KeyAscii > 57 Then
Beep
If KeyAscii <> 46 Then KeyAscii = 0 '小数点可以
End If
End Sub
Private Sub gd_KeyPress(KeyAscii As Integer)
If gd.Col = 2 Or gd.Col = 3 Then
select case keyascii
case asc("0") to asc("9"),asc("."),vbkeytab,vbkeyback
case else
MsgBox gd.Col & KeyAscii
KeyAscii = 0
end select
End If
If KeyAscii = 13 Then Exit Sub
If InStr(".1234567890", Chr(CStr(KeyAscii))) = 0 Then
KeyAscii = 0
End If
End Sub
If keyascii < Asc("0") Or keyascii > Asc("9") Then
keyascii = 0 '取消输入
End If
End Sub
只是整数