Results 1 to 2 of 2

Thread: Array

  1. #1
    Join Date
    Apr 2002

    Unanswered: Array

    I have values in my array. I was wondering if there is an
    easy way to calculate max, min, avg etc based on the
    values in the array ?


  2. #2
    Join Date
    Jan 2003
    Rockville, MD
    Hi Milan,

    Here's a subroutine to calculate the min, max, and avg of values in your array:

    Array is single-dimension.
    Array is of type "double".

    Sub ArrayMinMaxAvg (dblArray() As Double, dblAvg As Double, dblMax As Double, dblMin As Double)
       Dim intArrayPosition As Integer
       ' initialize min, max, and avg as the value of the first element
       dblAvg = dblArray(LBound(dblArray)) / (UBound(dblArray) - LBound(dblArray) + 1)
       dblMin = dblArray(LBound(dblArray))
       dblMax = dblArray(LBound(dblArray))
       ' continue through the rest of the array
       For intArrayPosition = LBound(dblArray) + 1 To UBound(dblArray)
          dblAvg = dblAvg + dblArray(intArrayPosition) / (UBound(dblArray) - LBound(dblArray) + 1)
          If dblMin > dblArray(intArrayPosition) Then
             dblMin = dblArray(intArrayPosition)
          End If
          If dblMax < dblArray(intArrayPosition) Then
             dblMax = dblArray(intArrayPosition)
          End If
    End Sub
    Hope this helps!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts