Private Sub Command1_Click() If Text1.Text = "" Then Exit Sub Text1.SetFocus End If ‘如果为空,要求重新输入。 If Len(Text1.Text) > 5 Then MsgBox "提示", vbOKOnly, "你输入的值太大" Text1.Text = "": Text1.SetFocus Exit Sub End If ‘如果太大,清空后再重新输入 If Int(Text1.Text) < 6 Then MsgBox "提示", vbOKOnly, "你输入的值太小" Text1.Text = "":Text1.SetFocus Exit Sub End If ‘如果太小,清空后再重新输入 Form2.Hide ‘关闭Form2 Form1.Show ‘打开Form1 Load Me End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) If Not (48 <= KeyAscii And KeyAscii <= 57 ) Then If KeyAscii <> 8 Then KeyAscii = 0 ‘容错,使输入的整数值有效 End If End If End Sub