1. Registered User
Join Date
Apr 2002
Posts
168

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 ?

Thanks

2. Registered User
Join Date
Jan 2003
Location
Rockville, MD
Posts
179
Hi Milan,

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

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

Code:
```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
Next
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
•