Write the program in VB.Net (not Web based) and have it accept user input of the amount, term and interest rate. Display the mortgage payment amount. Then, list the loan balance and interest paid for each payment over the term of the loan. The list will be longer than the screen, so use loops to display a partial list, hesitate, and then display more of the list. Insert comments to document the program.
I have created 4 buttons. Calculate, Clear, List, and Exit. The buttons all work, but the list does not. Not sure what i am doing wrong. Please help. Thank you
Public Class MortCalc
Private Sub clearForm()
txtAmount.Text = "Enter Amount"
txtRate.Text = "Enter Interest Rate"
txtYears.Text = "Enter Years"
txtMonthlyPayment.Text = ""
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
Dim txtLoan As Integer = 200000
Dim txtRate As Double = 5.35
Dim txtTerm As Integer = 30 * 12
Dim iRate As Double = txtRate / 100 / 12
Dim tTotal As Double = txtLoan * (iRate / (1 - (1 + iRate) ^ (-txtTerm)))
txtTotal.Text = Format(tTotal, "$#,##0.00")
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
clearForm()
End Sub
Private Sub btnList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnList.Click
'Calculate the Monthly Payment'
Dim dblAmount, dblMonthlyRate, dblMonths, dblMonthlyPayment As Double
'Convert input values to numeric values'
dblAmount = CDbl(txtAmount.Text)
dblMonthlyRate = CDbl(txtRate.Text) / 100 'allows interest rate to be entered whole number'
dblMonths = CDbl(txtYears.Text)
'Format input values'
txtAmount.Text = FormatCurrency(dblAmount)
txtRate.Text = FormatPercent(dblMonthlyRate)
txtYears.Text = FormatNumber(dblMonths)
'Calculate payment'
'Results for listbox should be new loan balance and interest rate'
Dim PVal, FVal, mPayments As Integer
Dim APR, iPayment, TotInt As Double
Dim pPayment, TotPrincipal, dblBalance As Double
PVal = dblAmount
FVal = 0
APR = dblMonthlyRate / 12
mPayments = dblMonths * 12
dblBalance = dblAmount
For period As Integer = 1 To mPayments
iPayment = IPmt(APR, period, mPayments, -PVal, FVal, 1)
pPayment = PPmt(APR, period, mPayments, -PVal, FVal, 1)
lstLoanInterest.Items.Add(FormatCurrency(TotPrincipal).PadRight(25) & FormatCurrency(iPayment).PadRight(25) & FormatCurrency(dblBalance).PadLeft(25))
Debug.WriteLine(" Pmnt #" & period & " -> Principle =" & FormatCurrency(TotPrincipal).PadRight(14) & " Int Paid for Payment #" & period & " is " & FormatCurrency(iPayment) & " Bal. =" & FormatCurrency(dblBalance))
TotInt = TotInt + iPayment
TotPrincipal = TotPrincipal + pPayment
Dim monthlyPayment As Double = CDbl(iPayment + pPayment)
dblBalance = dblBalance - (monthlyPayment - iPayment)
Next
lstLoanInterest.Items.Add(" _______________________________")
lstLoanInterest.Items.Add(" Total interest paid: " & FormatCurrency(TotInt))
lstLoanInterest.Items.Add(" _______________________________")
lstLoanInterest.Items.Add(" Total Paid after: " & mPayments & " Payments = " & FormatCurrency(TotInt + TotPrincipal))
lstLoanInterest.Items.Add(" _______________________________")
lstLoanInterest.Items.Add(" Last Payment is an interest payment of course, and it is " & FormatCurrency(iPayment))
'Format answer'
dblMonthlyPayment = CDbl(iPayment + pPayment)
txtMonthlyPayment.Text = FormatCurrency(dblMonthlyPayment)
End Sub
End Class

New Topic/Question
Reply




MultiQuote






|