Average of an array

Discussion in 'Code Samples & Tips' started by Erel, Mar 24, 2009.

  1. Erel

    Erel Administrator Staff Member Licensed User

    I was asked about calculating the average of values stored in an array.
    So here is the answer:
    Code:
    Sub Globals
        
    Dim values(0)
    End Sub

    Sub App_Start
        values() = 
    Array(100,90,80,90,79,95)
        
    Msgbox(calcAverage)
    End Sub
    Sub calcAverage
        sum = 
    0
        
    For i = 0 To ArrayLen(values())-1
            sum = sum + values(i)
        
    Next
        
    Return sum / ArrayLen(values())
    End Sub
     
  2. x7Q391kt

    x7Q391kt New Member Licensed User

    Thank you very much!
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice