然后求出3个数中的最小值?
帮忙改写一下我这段有问题的代码
谢谢
Private Sub Form_Click()
Dim num1 As Integer, small As Integer, i
For i = 1 To 3
num1 = InputBox("请输入第" + Str(i) + "个数")
small = num1
If num1 < small Then
small = num1
End If
next i
Text1.Text = small
End Sub
法一:
If Text1.Text = "" Then
MsgBox "输入框为空!"
Exit Sub
ElseIf Not IsNumeric(Trim(Text1))
Then
MsgBox "输入的数值有误!"
Exit Sub
End If
这个语句可以判断是不是空的,是不是数值
法二:
Dim shu As Double
If Text1.Text = "" Then
MsgBox "输入框为空!"
Exit Sub
ElseIf Not IsNumeric(Trim(Text1))
Then
MsgBox "输入的数值有误!"
Exit Sub
End If
shu = Val(Text1.Text)
Do
shu = shu - 1
Loop Until shu <= 0
If shu <> 0 Then
MsgBox "输入的值不是整型!"
Exit Sub
End If
让输入的数值不停的减1,直到小于0,或等于0,
如果是整数最后肯定等于0,如果是小数最后肯定小于0,
所以这时可以通过判断最后的差是否是0,来判断输入的数值是不是整数!
法三:
For i = 1 To 3
a(i) = InputBox("请输入第" & CStr(i) & "个数")
If a(i)>fix(a(i)) then
MsgBox("请输入一个整数")
i=i-1
End If
Next
法四:
tpstr = Val(InputBox("请输入第1个数"))
small = CInt(tpstr)
If tpstr <> small Then MsgBox "请输入整数"
法五:
If Val(Text1.Text) <> Int(Text1.Text) Then MsgBox "Error!"
法六:
If Not IsNumeric(TxtInput.Text) or InStr(TxtInput.Text,".")<> 0 Then
msgbox"必须输入正数!"
TxtInput.SetFocus
End If