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.

Call InputData(principal, yearlyRate, numMonths)<br />

Call ShowAmortSched(principal, yearlyRate, numMonths)<br />

End Sub<br />

Private Sub cmdPayment_Click()<br />

Dim principal As Single ‘Amount of loan<br />

Dim yearlyRate As Single ‘Annual rate of interest<br />

Dim numMonths As Integer ‘Number of months to repay loan<br />

Call InputData(principal, yearlyRate, numMonths)<br />

Call ShowPayment(principal, yearlyRate, numMonths)<br />

End Sub<br />

Private Sub cmdQuit_Click()<br />

End<br />

End Sub<br />

Private Sub cmdRateTable_Click()<br />

Dim principal As Single ‘Amount of loan<br />

Dim yearlyRate As Single ‘Annual rate of interest<br />

Dim numMonths As Integer ‘Number of months to repay loan<br />

Call InputData(principal, yearlyRate, numMonths)<br />

Call ShowInterestChanges(principal, yearlyRate, numMonths)<br />

End Sub<br />

Private Sub InputData(prin As Single, yearlyRate As Single, numMs As Integer)<br />

Dim percentageRate As Single, numYears As Integer<br />

‘Input the loan amount, yearly rate of interest, <strong>and</strong> duration<br />

prin = Val(txtAmt.Text)<br />

percentageRate = Val(txtApr.Text)<br />

numYears = Val(txtYrs.Text)<br />

yearlyRate = percentageRate / 100<br />

numMs = numYears * 12<br />

End Sub<br />

Private Function Payment(prin As Single, mRate As Single, numMs As Integer) As Single<br />

Dim payEst As Single<br />

If numMs = 0 Then<br />

payEst = prin<br />

ElseIf mRate = 0 Then<br />

payEst = prin / numMs<br />

Else<br />

payEst = prin * mRate / (1 - (1 + mRate) ^ (-numMs))<br />

End If<br />

If payEst Round(payEst, 2) Then<br />

Payment = Round(payEst + .005, 2) ‘round up to nearest cent<br />

End If<br />

End Function<br />

Private Sub ShowAmortSched(prin As Single, yearlyRate As Single, numMs As Integer)<br />

Dim msg As String, startMonth As Integer, mRate As Single<br />

Dim monthlyPayment As Single, totalInterest As Single<br />

Dim yearInterest As Single, oldBalance As Single<br />

Dim monthNum As Integer, newBalance As Single<br />

Dim principalPaid As Single, interestPaid As Single<br />

Dim reducPrin As Single, loanYears As Integer<br />

‘Display amortization schedule<br />

A Case Study: Analyze a Loan 151

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

Saved successfully!

Ooh no, something went wrong!