Microsoft Visual Basic 2015: RELOADED (6th Edition) pg 401 Create an application
ID: 3594609 • Letter: M
Question
Microsoft Visual Basic 2015: RELOADED (6th Edition) pg 401 Create an application that displays a monthly payment on a loan. The application should also display the amount applied to the loan’s principal each month and the amount that represents interest. Use the following names for the solution and project, respectively: Loan Solution and Loan Project. Save the solution in the VbReloaded2015Chap07 folder. Change the form file’s name to Main Form.vb. The application should use annual interest rates from 2% through 10% in increments of 1%, and use terms from 1 through 30 years. You can use the Financial.PPmt method to calculate the portion of the payment applied to the principal each month. The method’s syntax is Financial.PPmt(Rate, Per, NPer, PV). In the syntax, Rate is the interest rate, NPer is the number of payment periods, and PV is the present value of the loan. The Per argument is the payment period for which you want to calculate the portion applied to the principal. The Per argument must be a number from 1 through NPer. The method returns the calculated value as a Double number. You can either create your own interface or create the one shown in Figure 7-44; the figure shows a sample run of the application. The combo box that gets the interest rate is the DropDown style. The combo box that gets the term is the DropDownList style. The text box that displays the output has its Multiline and ReadOnly properties set to True and its ScrollBars property set to Vertical. (1, 2, 4–7)
Explanation / Answer
Public Class Form1
Private Sub btnDisplayPrincipal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplayPrincipal.Click
Dim MonthlyPayments As Double
Dim bloanTotal As Double = 3000
Dim rate As Double = 0.007
Dim interest As Double
Dim toPrincipal As Double
Dim toInterest As Double
Dim counter As Integer
Do
'Calculate the monthly payments
MonthlyPayments =
Math.Abs(Financial.Pmt(0.07 / 12, 12, 3000))
TextBox1.Text = MonthlyPayments.ToString("C2")
counter = counter + 1 'add one to the counter
interest = bloanTotal + rate 'calculate interest rate from payment that will only count as interest
toInterest = MonthlyPayments - interest ' amount of monthly payment going towards interest
toPrincipal = MonthlyPayments - toInterest ' amount of monthly payment going towards principal
bloanTotal = bloanTotal - toPrincipal ' new balance after deducting principal from beginning balance
'concatinate principal and interest string and create a new line
lblMonthlyPayment.Text = toPrincipal.ToString & " " & toInterest.ToString & ControlChars.NewLine
'exit Loop once counter has reached 12 and Loan amount has reached zero
If counter = 12 Then
Exit Do
End If
Loop
End Sub
Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class