19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Dim yrs As String, pay As Single, pymnt As String<br />

‘Display monthly payment amount<br />

mRate = yearlyRate / 12 ‘monthly rate<br />

prn = FormatCurrency(prin)<br />

apr = FormatNumber(yearlyRate * 100)<br />

yrs = FormatNumber(numMs / 12, 0)<br />

pay = Payment(prin, mRate, numMs)<br />

pymnt = FormatCurrency(pay)<br />

picDisp.Cls<br />

picDisp.Print “The monthly payment for a “& prn & “loan at “<br />

picDisp.Print apr & “% annual rate of interest for “;<br />

picDisp.Print yrs & “years is “& pymnt<br />

End Sub<br />

COMMENTS<br />

1. Tasks 3.1 <strong>and</strong> 3.2 are performed by functions. Using functions to compute these<br />

quantities simplifies the computations in ShowAmortSched.<br />

2. Because the payment was rounded up to the nearest cent, it is highly likely that<br />

the payment needed in the final month to pay off the loan will be less than the<br />

normal payment. For this reason, ShowAmortSched checks if the balance of the<br />

loan (including interest due) is less than the regular payment, <strong>and</strong> if so, makes<br />

appropriate adjustments.<br />

3. The st<strong>and</strong>ard formula for computing the monthly payment cannot be used if<br />

either the interest rate is zero percent or the loan duration is zero months.<br />

Although both of these situations do not represent reasonable loan parameters,<br />

provisions are made in the function Payment so that the program can h<strong>and</strong>le<br />

these esoteric situations.<br />

SUMMARY<br />

1. A Do loop repeatedly executes a block of statements either as long as or until a<br />

certain condition is true. The condition can be checked either at the top of the<br />

loop or at the bottom.<br />

2. The EOF function tells us if we have read to the end of a file.<br />

3. As various items of data are processed by a loop, a counter can be used to keep<br />

track of the number of items, <strong>and</strong> an accumulator can be used to sum numerical<br />

values.<br />

4. A flag is a Boolean variable, used to indicate whether or not a certain event has<br />

occurred.<br />

5. A For...Next loop repeats a block of statements a fixed number of times. The<br />

control variable assumes an initial value <strong>and</strong> increments by one after each pass<br />

through the loop until it reaches the terminating value. Alternative increment<br />

values can be specified with the Step keyword.<br />

PROGRAMMING PROJECTS<br />

1. Write a program to display a company’s payroll report in a picture box. The program<br />

should read each employee’s name, hourly rate, <strong>and</strong> hours worked from a<br />

<strong>Programming</strong> Projects 153

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!