Using Parameter Arrays
Sub GetAverageSalary(strDepartment As String, _
ParamArray currSalaries() As Variant)
Dim sngTotalSalary As Single
Dim sngAverageSalary As Single
Dim intCounter As Integer
For intCounter = 0 To UBound(currSalaries())
sngTotalSalary = sngTotalSalary + currSalaries(intCounter)
Next intCounter
sngAverageSalary = sngTotalSalary / (UBound(currSalaries()) + 1)
msgBox strDepartment & " has an average salary of " & _
sngAverageSalary
End Sub
Sub ParaArray()
Call GetAverageSalary("Accounting", 6, 2, 3, 2, 8)
End Sub
Related examples in the same category