963 Arrays
39.7 Arrays as Parameters to Functions
Arrays can be used as parameters to functions. The following set of
functions and subroutines presents an improved version of MoreDynPV.
Notice how mach easier it is to read the main macro NewDynPV
when all the auxiliary tasks are relegated to separate functions and
subroutines.
A function ComputePV(CF(), n) is used to compute the present value
of a series of cash fl ows contained in an array of Doubles.
Function ComputePV(CF() As Double, n As
Integer) As Double
Dim Temp As Double, i As Integer
Temp = 0
For i = 1 To n
Temp = Temp + CF(i) / 1.05 ^ i
Next i
ComputePV = Temp
End Function
A subroutine GetCF(CF(), n) is used to query the user for the cash
fl ow values and store them in the CF array.
Sub GetCf(CF() As Double, n As Integer)
Dim i As Integer
For i = 1 To n
CF(i) = InputBox(“Enter value for period “ _
& i, “Present value calculator”, CF(i))
Next i
End Sub