3 Replies - 1098 Views - Last Post: 12 November 2012 - 04:50 AM Rate Topic: -----

#1 mitchstokes225  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 05-November 09

My Mortgage Calculator math is off from online calculators

Posted 11 November 2012 - 11:45 AM

My assignment is to create a mortgage calculator.
Requirements:
Loan Amount Text Box
Fixed Interest Rate Text Box
Years Combo Box

To be calculated:
Monthly Payments
Number of Payments
Payment Total
Interest Total

Buttons:
Calculate and Exit

I have the correct calculations appearing in the Monthly Payments and Number of Payments. But when I try to use a pmt function for payment total and interest total, I can't get it to work. They way I have it constructed to calculate those two fields, the math is off from the calculators I am using to help work the math to check it. Online Calculator

Here is my code... Things I need assistance on: Payment Total And Interest Total. Either help with how to do the pmt function or help with fixing my code that I currently have.

Public Class Form1
   
    Dim Nullable As TextBox
    Private Sub Form_load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Me.cboYears.SelectedText = "30"

    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

        'Ensure that fields are entered to stave off errors running program.
        If String.IsNullOrEmpty(txtLoanAmount.Text) Then
            MessageBox.Show("Missing Amount", "Please Enter Amount of Loan")
        ElseIf String.IsNullOrEmpty(txtInterestRate.Text) Then
            MessageBox.Show("Missing Interest", "Please Enter Fixed Interest Rate")
        Else

            Dim LoanAmount As Double
            Dim InterestRate As Double
            Dim Years As Double
            Dim Months As Double

            LoanAmount = CDbl(txtLoanAmount.Text)
            InterestRate = txtInterestRate.Text / 12
            Years = CDbl(cboYears.Text)
            Months = cboYears.Text * 12


            'Monthly Payment Calculations and Number of Monthly Payments.
            txtMonthPayment.Text = Pmt(InterestRate, Months, -LoanAmount)
            txtMonthPayment.Text = Format(CDbl(txtMonthPayment.Text), "$###,###,###.##")
            txtNumPayment.Text = Months

            'Payment Total Calculations.
            txtPaymentTotal.Text = txtMonthPayment.Text * txtNumPayment.Text
            txtPaymentTotal.Text = Format(CDbl(txtPaymentTotal.Text), "$###,###,###.##")


            'Total of Interests Paid.
            txtInterestTotal.Text = txtPaymentTotal.Text - txtLoanAmount.Text
            txtInterestTotal.Text = Format(CDbl(txtInterestTotal.Text), "$###,###,###.##")

        End If

    End Sub
End Class



One common problem I get when trying to do pmt function with the payment total is an error about infinite number. Which I thought was weird, so I figured I was blowing something up. I can't find a clear post about how pmt function works, or a post where someone did a similar mortgage calculator.

Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: My Mortgage Calculator math is off from online calculators

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5480
  • View blog
  • Posts: 11,762
  • Joined: 02-June 10

Re: My Mortgage Calculator math is off from online calculators

Posted 11 November 2012 - 01:56 PM

Your assignment is to do this in VB6? You're deliberately going to school to learn a language that's been dead for a decade? Should this be moved to VB.NET?

Please read: This is not the VB.NET forum
Please read: Is learning VB6 now a complete waste of time? (Yes)

Try changing your doubles to decimals. Doubles are notorious for rounding error which might be compounding over the repetitive nature of your calculations.

When you say the figures are 'off'... by how much? A few pennies a year or hundreds of dollars a month?
Was This Post Helpful? 0
  • +
  • -

#3 mitchstokes225  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 05-November 09

Re: My Mortgage Calculator math is off from online calculators

Posted 11 November 2012 - 04:59 PM

View PosttlhIn`toq, on 11 November 2012 - 01:56 PM, said:

Your assignment is to do this in VB6? You're deliberately going to school to learn a language that's been dead for a decade? Should this be moved to VB.NET?

Please read: This is not the VB.NET forum
Please read: Is learning VB6 now a complete waste of time? (Yes)

Try changing your doubles to decimals. Doubles are notorious for rounding error which might be compounding over the repetitive nature of your calculations.

When you say the figures are 'off'... by how much? A few pennies a year or hundreds of dollars a month?



The class is an event driven programming class, and it is what it is. I am learning Visual Basic, not .net. I've had COBOL and C++ also. I don't mind taking it, makes my skills that much stronger. And I've still seen it in play. I don't plan on being a programmer, I'm a QA Analyst, I'm just getting a degree that makes sense for me.


I think it's the online calculator that's broken. I just ran my professors numbers from his tutorial through it and it's off. And the amounts off are inconsistent. Anywhere from .4 to 4 dollars. I've not seen more than that or less than that.

I tried to do them as decimal rather than double, and Visual Studio kept bi%@hing at me.

This post has been edited by mitchstokes225: 11 November 2012 - 05:04 PM

Was This Post Helpful? 0
  • +
  • -

#4 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,771
  • Joined: 26-March 09

Re: My Mortgage Calculator math is off from online calculators

Posted 12 November 2012 - 04:50 AM

The code you've posted is in fact VB.Net, so technically you are in the wrong forum.

Have a look at the following links to see if anything helps

Link 1
Link 2
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1