Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 48 To 57 '0-9
Text1.SetFocus
Dim strTmp As String
strTmp = Text1.Text & Chr(KeyAscii)
If Val(strTmp) > 100 Then
MsgBox "该TextBox输入的值不允许大于100"
KeyAscii = 0
End If
Exit Sub
Case 8
Exit Sub
Case 46
Exit Sub
Case Else
KeyAscii = 0
End Select
End Sub
'这里限制了只能输入数字,且输入数字的最大值不得超过100
如果你需要从1开始的话,可以在change事件中写入代码:If Left(Text1.Text, 1) = 0 Then Text1.Text = ""
[此贴子已经被作者于2007-10-29 9:10:16编辑过]