如何获取数组中值最大的元素?
例:A(3, 2, 1), 怎样把3提出来?如果是100个数组元素的话。
有没有专门的函数?
谢谢。

解决方案 »

  1.   

    Dim a() As String
    Dim max As String
    Dim i As Integer
    a() = Split("3,5,2,1", ",") '生成一个测试数组
    For i = LBound(a) To UBound(a)
        If a(i) > max Then max = a(i)
    Next
    Debug.Print max
      

  2.   

    Function max(ParamArray a()) As Double
    max = a(LBound(a))
    Dim i As Long
    For i = LBound(a) To UBound(a)
    If max < a(i) Then max = a(i)
    Next
    End FunctionPrivate Sub Command2_Click()
    MsgBox max(2, 11, 5, 18, 3, 4, 9)
    End Sub