Practice Exercise 7
Parameter Passing

Objective: To become familiar with parameter passing.


Exercise 1:

Write a procedure that computes the value of an investment p after n years of interest at rate r compounded quarterly. Write a brief program to make use of this procedure. Should your procedure be a sub or a function? Should the parameters be passed by value or by reference?

Note: Future Value = p*(1 + (r / 4))^(4 * n)


Exercise 2:

Given the following procedure body, write a heading that declares ByVal and ByRef parameters as necessary. (Hint: Make a list of all identifiers in the procedure and notice which ones aren't declared locally.

Private Sub getAverage( . . . parameters . . . )
    Dim sngSales1 as Single
    Dim sngSales2 as Single

    lblResults.Text &= "Department " & intDepNumber & vbCrLf
    sngSales1 = txtSales1.Text
    sngSales2 = txtSales2.Text
    lblResults.Text &= "Has weekly sales of " & sngSales1 & " and " & sngSales2 & "." & vbCrLf
    sngAverageSales = (sngSales1 + sngSales2) / 2.0
    lblResults.Text &= "For an average of " & sngAverageSales & "." & vbCrLf

End Sub


Demo

 

sln File