devxlogo

ArrayAvg – The average of an array of any type

ArrayAvg – The average of an array of any type

' The average of an array of any type'' FIRST and LAST indicate which portion of the array' should be considered; they default to the first' and last element, respectively' if IGNOREEMPTY argument is True or omitted,' Empty values aren't accounted forFunction ArrayAvg(arr As Variant, Optional First As Variant, _    Optional Last As Variant, Optional IgnoreEmpty As Boolean = True) As Variant    Dim index As Long    Dim sum As Variant    Dim count As Long    If IsMissing(First) Then First = LBound(arr)    If IsMissing(Last) Then Last = UBound(arr)        ' if arr isn't an array, the following statement raises an error    For index = First To Last        If IgnoreEmpty = False Or Not IsEmpty(arr(index)) Then            sum = sum + arr(index)            count = count + 1        End If    Next        ' return the average    ArrayAvg = sum / countEnd Function

See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist