# Mortgage Calculator help

Page 1 of 1

## 2 Replies - 4043 Views - Last Post: 20 October 2009 - 10:49 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=133124&amp;s=7464d58952f72528af4e5214b2ec661b&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 hollywoood69

Reputation: 0
• 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)
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(" Total interest paid: " & FormatCurrency(TotInt))
lstLoanInterest.Items.Add(" Total Paid after: " & mPayments & "  Payments = " & FormatCurrency(TotInt + TotPrincipal))
lstLoanInterest.Items.Add(" Last Payment is an interest payment of course, and it is " & FormatCurrency(iPayment))
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

• Suitor #2

Reputation: 13954
• Posts: 55,700
• 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?

### #3 hollywoood69

Reputation: 0
• 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?