我試圖找到3個輸入的最大值。問題不在算法中,因爲當我在python中創建相同的腳本時,它工作得很好。問題是它不能按預期工作。我會寫一些情景和結局怎樣爲:查找3個輸入的最大值VBA
8 5月12日 - 最大:12
5 8 12 - 最大:12
12 5 8 - 最大:8
12 8 5 - 最大:8
5 12 8 - 最大:8
8 12 5 - 最大:8
100 22 33 - 最大:33
22 3 100 - 最高:100
100 22 3 - 最大:22
它似乎它適用於q請結合一些組合,但不適合每個人。我還沒有設法找到一個模式,我不知道什麼是錯的。
我附上代碼:
Sub Maxthree()
'Calculates the maximum of three numbers'
Dim x, y, z As Single
x = InputBox("Enter the first number!")
y = InputBox("Enter the second number!")
z = InputBox("Enter the third number!")
MsgBox ("X: " & x & " Y: " & y & " Z: " & z)
If x > y Then
If x > z Then
MsgBox ("the maximum is : " & x)
Else
MsgBox ("the maximum is : " & z)
End If
Else
If y > z Then
MsgBox ("the maximum is : " & y)
Else
MsgBox ("the maximum is : " & z)
End If
End If
End Sub
注意,聲明變量爲'點心的x,y和z如Single'將宣佈'x','y'如'Variant'和只有'z'作爲'Single' – 2014-12-13 21:53:09