在validate事件中
if val(text1)< 0 and val(text1)<> int(val(text1)) then
msgbox "不是合法的正整数"
cancel = true
End If
if val(text1)< 0 and val(text1)<> int(val(text1)) then
msgbox "不是合法的正整数"
cancel = true
End If
解决方案 »
- 你的礼物我很喜欢,谢谢
- 100分相送,请问VB中如何实现四次方程求根......
- xp下怎么取得我的文档的路径
- 请教,windows系统自带的计划任务,如何能够通过API调用出来?
- 如何杀掉进程中里运行的excel.exe ??????
- 在formload 事件中,给一控件数组Command(i).tag="as"这么写为什么会不起用?
- 什么是“开发文档”?怎么写“开发文档”?
- 关于vb考试系统的一个问题!
- WIN32API函数的dll……求救
- ~~~h-e--l--p.......~~~~~~ 锁类型为adlockpessimistic 意味着多人不许修改,添加,但....这是为什么????? 求助: foolishtiger(吴文智),阿木等高手!!谢谢!!!
- 关于字符串加密的问题.
- 一个webbrowser分析代码的问题,大家帮帮忙
if val(text1)< 0 or val(text1)<> int(val(text1)) then
MsgBox "请输入整数"
Exit Sub
End If
If CLng(Text1.Text) < 0 Then
MsgBox "请输入正整数"
Exit Sub
End If
private sub text1_keypress(byval keyascii as integer)
select case keyascii
case "0" to "9",8,13 '8是退格键,可以让用户删除;13是回车
case else
keyascii=0
end select此法限制用户只能输入数字键。
case asc("0") to asc("9"),8,13 '8是退格键,可以让用户删除;13是回车
if val(text1)< 0 and val(text1)<> int(val(text1)) then
msgbox "不是合法的正整数"
cancel = true
End If
Const ValidKeyInput As String = "0123456789abcdefABCDEF"
上面的字符串可以任意改动为想允许输入的范围!然后在该控件的KeyPress事件里加入:
If (KeyAscii > 31) Then
If (InStr(ValidKeyInput, Chr$(KeyAscii)) = 0) Then
MsgBox "输入无效!", vbExclamation, "错误"
KeyAscii = 0
End If
End If