Option Explicit
Function AVERAGE(ByRef Number() As Double) As Double
Dim iMaxNum As Double, i As Integer
For i = LBound(Number) To UBound(Number)
iMaxNum = iMaxNum + Number(i)
Next i
AVERAGE = iMaxNum / (UBound(Number) + 1)
End Function
Contoh penggunaan fungsi untuk memperoleh nilai rata-rata dari sebuah array
Private Sub Command1_Click()
Dim iArray(3) As Double
iArray(0) = 588
iArray(1) = 67
iArray(2) = 66
iArray(3) = 4
MsgBox "The Average is: " & AVERAGE(iArray)
End Sub