# Visual Basic mortgage calculator

Page 1 of 1

## 3 Replies - 757 Views - Last Post: 19 October 2017 - 10:48 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=407002&amp;s=4ec44701805d8c3695347325e16d6ec4&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Nardilla

Reputation: 0
• Posts: 4
• Joined: 19-October 17

# Visual Basic mortgage calculator

Posted 19 October 2017 - 08:20 AM

****Microsoft Visual Basic**** Mortgage Calculator****Create an application that calculates and displays three monthly mortgages payments.The application should use the loan amount and annual interest rate provided by the user with terms of 15 years, 25 years, and 30 years. The application should also display the total amount paid at the end of 15 years, 25 years and 30 years.

My code

```Private Sub Button2_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub

Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
'Displays the monthly mortgage payments

'Variables

Dim dblLoanAmount As Double
Dim dblRate As Double
Dim dblMonthlyPayment As Double
Dim dblFullTerm As Double

'store imput variables
Double.TryParse(txtLoanAmount.Text, dblLoanAmount)
Double.TryParse(lstRates.SelectedItem.ToString, dblRate)
dblRate = dblRate / 100

'Monthly Payment
Dim intYears As Integer = 15
Do Until intYears <= 30
If (intYears = 15) Then
intYears += 10
Else
intYears += 5
End If
Loop

dblMonthlyPayment = -Financial.Pmt(dblRate / 12, intYears * 12, dblLoanAmount,)
lblMonthlyPayment.Text = lblMonthlyPayment.Text & intYears.ToString &
"years:     " & dblMonthlyPayment.ToString("c2") &
ControlChars.NewLine
```

My problem is the loop: the only result a got is for 15 years

This post has been edited by andrewsw: 19 October 2017 - 08:23 AM
Reason for edit:: added missing [code][/code] tags

Is This A Good Question/Topic? 0

## Replies To: Visual Basic mortgage calculator

### #2 andrewsw

• blow up my boots

Reputation: 6492
• Posts: 26,276
• Joined: 12-December 12

## Re: Visual Basic mortgage calculator

Posted 19 October 2017 - 08:28 AM

Please wrap code in code tags, it shows how to do this directly in the box where you type your posts. I've added them for you.

That is VB.NET code, not VB6. Moving to VB.NET forum.

```    Dim intYears As Integer = 15 'you set the value to 15...
Do Until intYears <= 30 ' this loop is never entered because the condition is already true (15 <= 30)
```

Note also that the loop will achieve very little, only adding 10 or 5 to intYears. Nothing else happens within the loop.

### #3 Nardilla

Reputation: 0
• Posts: 4
• Joined: 19-October 17

## Re: Visual Basic mortgage calculator

Posted 19 October 2017 - 08:54 AM

```Dim intYears As Integer
Do
If (intYears = 15) Then
intYears += 10
Else
intYears += 5
End If
Loop Until intYears >= 30

dblMonthlyPayment = -Financial.Pmt(dblRate / 12, intYears * 12, dblLoanAmount,)
lblMonthlyPayment.Text = lblMonthlyPayment.Text & intYears.ToString &
"years:     " & dblMonthlyPayment.ToString("c2") &
ControlChars.NewLine
```

Thank you! When I changed to this way I only got the results for 30 years.

### #4 andrewsw

• blow up my boots

Reputation: 6492
• Posts: 26,276
• Joined: 12-December 12

## Re: Visual Basic mortgage calculator

Posted 19 October 2017 - 10:48 AM

Work it through with pen and paper. Why does the value skip through to 30? What happens to all the values before that?

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }