如何在vb文本框中限制输入数值的大小

比如说只能在TEXE1中输入小于100的数字。
我正在自学VB,很多问题不太明白,希望可以得到你们的帮助,谢谢。

Private Sub Text1_Change()
On Error Resume Next
If Val(Trim(Text1.Text)) > 100 Then
MsgBox "输入数字过大,请重新输入"
Text1.Text = ""
End If
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii >= 33 Then
If KeyAscii <= vbKey9 And KeyAscii >= vbKey0 Then
Else
KeyAscii = 0
MsgBox "请输入数字!"
End If
End If
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-03-20
加入if val(text1.text)>=100 then
msgbox "提示内容",16,"请输入小于100的数!"
第2个回答  2008-03-20
Private Sub Text1_Change()
If Len(Text1.Text) > 0 Then
If CVar(Text1.Text) < 100 Then
Else
Text1.Text = 99
End If
End If
End Sub

msdn:
mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\98VS\2052\vbenlr98.chm::/HTML/vagrptypeconversion.htm
第3个回答  2008-03-20
楼上的答案已经非常标准了。
不过我觉得要是加上一个严整是否输入的是数字就更好些了.呵呵.