Mortgage Calculator help

Can not display a list...not sure what i am doing wrong

Page 1 of 1

2 Replies - 2911 Views - Last Post: 20 October 2009 - 10:49 AM Rate Topic: -----

#1 hollywoood69  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 09-April 09

Mortgage Calculator help

Posted 19 October 2009 - 10:09 PM

Hello everyone! I am really new with this vb.net stuff. I have to create a mortgage calculator (I know we have killed this mortgage calculator). Has to display an amortization table to display the list after doing the calculation. Here is the actual assignment:

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



Is This A Good Question/Topic? 0
  • +

Replies To: Mortgage Calculator help

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9047
  • View blog
  • Posts: 33,955
  • Joined: 12-June 08

Re: Mortgage Calculator help

Posted 20 October 2009 - 07:28 AM

What do you mean the "all work, but the list does not.". How is it not working?
Was This Post Helpful? 0
  • +
  • -

#3 hollywoood69  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 09-April 09

Re: Mortgage Calculator help

Posted 20 October 2009 - 10:49 AM

What I meant was everything but the list is working. I can input a number. I can calculate the total, and I can get an output....but when I try to run the list...I get stuck?? Any suggestions?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1