比较三个变量的大小。
比如a(0)=7 a(1)=6 a(2)=7
则n=7
怎么样用一个最简单效率最高的方式得出这样的结果。谢谢。
[解决办法]
function max(x1 as long,x2 as long)as long
if x1>x2 then
max=x1
else
max=x2
end if
end function
调用:
dim mMax as long
mMax=max(max(x1,x2),x3)
[解决办法]
Option Explicit
Private Function MaxItem(ByRef x() As Integer) As Integer
Dim n As Integer, i As Integer
For i = LBound(x) To UBound(x)
If x(i) > n Then n = x(i)
Next i
MaxItem = n
End Function
Private Sub Command1_Click()
Dim a(2) As Integer
a(0) = 7
a(1) = 6
a(2) = 7
MsgBox MaxItem(a)
End Sub