在keydown事件中写下以下代码:
if keycode<48 or keycode>57 then
msgbox "只能输入数字"
exit sub
end sub
这样可以判断是不是数字,但问题是非法字符还是输进去了
以前用delphi的时候这样的代码就可以控制了的
vb应该怎样控制啊?
if keycode<48 or keycode>57 then
msgbox "只能输入数字"
exit sub
end sub
这样可以判断是不是数字,但问题是非法字符还是输进去了
以前用delphi的时候这样的代码就可以控制了的
vb应该怎样控制啊?
解决方案 »
- 急,一个关于excel的问题啊!
- 请教高手,在屏幕上托拽文件并在form中的label里显示出这个文件的地址,应该调用哪一个api呢?
- 如果用VB采集网页中的链接
- 各位大虾,进来帮帮忙啊 !!!急!!!!
- 各位兄弟给点意见
- VB和VB。NET有什么主要分别??
- 一个初级问题:如何使DriveListBox与FileListBox同步,做一个类似于资源管理器?
- datareport 中一行显示不下,我想自动换行,选中cangrow后,两边的竖线怎么处理
- 这段程序有错吗?
- VB中怎样读写注册表??
- 连接数据库错误
- (急)在TextBox中有一段文字自动换行,要在换行处输入一个回车键,让它显示一个空白行,怎么实现?
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
End If
End Sub
这样就可以只能输入数字了!
InputNumeric KeyAscii, Text1
End Sub'*****************************************************************
'文本框只能输入数字Public Sub InputNumeric(KeyAscii As Integer, txtItem As TextBox)
Select Case KeyAscii
Case Asc("-") '允许负数
If txtItem.SelStart = 0 Then
If Left(txtItem.Text, 1) = "-" Then
KeyAscii = 0
Beep
End If
Else
KeyAscii = 0
Beep
End If
Case 8
'无变化,退格键不屏蔽
Case Asc(" ") '32
If txtItem.SelLength = 0 Then
KeyAscii = 0
End If
Case Asc(".") '46 '允许小数点
If InStr(txtItem.Text, ".") Then
KeyAscii = 0
End If
Case Is < Asc(0) '48
KeyAscii = 0
Case Is > Asc(9) '57
KeyAscii = 0
End Select
End Sub
If KeyAscii > 44 And KeyAscii < 58 And KeyAscii <> 47 Then
KeyAscii = 0
End If
End Sub你可以写个代码看你要输入的范围按键的 KeyAscii 数
Private Sub Text1_KeyPress(KeyAscii As Integer)
Text1 = KeyAscii
End Sub
If Len(Text1.Text) = 0 And KeyAscii = 46 Then KeyAscii = 0
If InStr(1, Text1.Text, ".") <> 0 And KeyAscii = 46 Then KeyAscii = 0
If KeyAscii = 8 Or KeyAscii = 46 Then Exit Sub
If Not IsNumeric(Chr(KeyAscii)) Then KeyAscii = 0
End Sub
-----------------------------
可以有小数点,BACKSPACE ,DEL,判断一个不能为小数点,屏蔽多次输入小数点