Using Parameter Arrays : Call « Language Basics « VBA / Excel / Access / Word






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

1.Use Call to invoke another sub module
2.Using Procedures and Subprocedures