Share this Page URL

A VBA Language Primer > Scope - Pg. 420

assigning it to the function name). Use the Function keyword in the first and last lines of the function body. Call a function just as you would a subprocedure, except that you need a variable to hold the value that the function passes back (Example 18-20). Example 18-20. Calling a Function Dim dblThisArea As Double dblThisArea = CalcCircleArea(2.5) ' dblThisArea = PI * (2.5^2) You can choose to ignore a function's return value. In this case, you don't need to surround its parameter list with parentheses. Any time you want to assign the return value to a variable, pa- rentheses are required around the function's parameter list. The return values of one or more function calls can be used in place of variables in calculations, or as parameters to other function or subprocedure calls (Example 18-21). Example 18-21. Using Return Values from Function Calls dblCylinderVolume = CalcCircleArea(2.5) * dblLength dblCylinderVolume = CalcCylinderVolume(CalcCircleArea(2.5), dblLength)