Erel B4X founder Staff member Licensed User Longtime User Mar 24, 2009 #1 I was asked about calculating the average of values stored in an array. So here is the answer: Code: Copy 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
I was asked about calculating the average of values stored in an array. So here is the answer: Code: Copy 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