3 Replies - 491 Views - Last Post: 19 October 2017 - 10:48 AM Rate Topic: -----

#1 Nardilla  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • 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  Icon User is online

  • the case is sol-ved
  • member icon

Reputation: 6379
  • View blog
  • Posts: 25,774
  • 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.
Was This Post Helpful? 1
  • +
  • -

#3 Nardilla  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • 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.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • the case is sol-ved
  • member icon

Reputation: 6379
  • View blog
  • Posts: 25,774
  • 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?
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1