Chapter 11: Mastering VBA Data Types and Procedures
443
The completed CalcExtendedPrice function is shown in Figure 11.11. Notice how this func-
tion’s parameters are defined in the function’s declaration statement. The parameters are separated
by continuation characters (a space followed by an underscore) to make the code easier to read.
FIGURE 11.11
The completed CalcExtendedPrice function
Calling a function and passing parameters
Now that you’ve completed the function, it’s time to test it.
Normally, a function call comes from a form or report event or from another procedure, and the
call passes information as parameters. The parameters passed to a procedure are often variables or
data taken from a form’s controls. You can test this function by going to the Immediate window
and using hand-entered values as the parameters.
Follow these steps to test the function:
- Press Ctrl+G to display the Immediate window.
- Enter? CalcExtendedPrice(5, 3.50, .05).
This statement passes the values as 5, 3.50, and .05 (5 percent) to the Quantity,
Price, and DiscountPercent parameters, respectively. CalcExtendedPrice
returns 16.625 using those values, as shown in Figure 11.12.
- Close the Immediate window and the VBA window and return to the Database window.