CODE
Option Strict Off
Option Explicit On
Public Class frmMain
'declaring the module-level variables
Private mdblDownPaymentTotal, mdblClosingCostTotal, mdblCashtoCloseTotal, mdblPrincipalInterestTotal, mdblPropertytaxesTotal, _
mdblInsuranceTotal, mdblMonthlyPaymentTotal, mdblperiod As Double
Private mdblPurchasePrice, mdblInterestRate As Double
Private Sub btnCalculate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
'accept the purchase price input
mdblPurchasePrice = System.Convert.ToDouble(txtPurchasePrice.Text)
txtPurchasePrice.Text = mdblPurchasePrice.ToString("c")
'accept the Interest rate input, send to mdblinterestrate as #.## while display full number
mdblInterestRate = System.Convert.ToDouble(txtInterestRate.Text / 100)
txtInterestRate.Text = mdblInterestRate * 100.ToString("##")
'determines the downpayment
mdblDownPaymentTotal = (mdblPurchasePrice * 0.2)
lblDownPaymentTotal.Text = mdblDownPaymentTotal.ToString("c")
''determines the closing cost
mdblClosingCostTotal = (mdblPurchasePrice * 0.025)
lblClosingCostTotal.Text = mdblClosingCostTotal.ToString("c")
' determines cash to close
mdblCashtoCloseTotal = (mdblClosingCostTotal + mdblDownPaymentTotal)
lblCashtoCloseTotal.Text = mdblCashtoCloseTotal.ToString("c")
'determine the principal and interest
mdblperiod = 360
'mdblPrincipalInterestTotal = Financial.Pmt(0.07, 360, 1000, 0)
mdblPrincipalInterestTotal = Financial.Pmt(mdblInterestRate, mdblperiod, mdblPurchasePrice, 0)
mdblPrincipalInterestTotal = System.Math.Abs(mdblPrincipalInterestTotal)
lblPrincipalInterestTotal.Text = mdblPrincipalInterestTotal.ToString("c")
'determine property taxes
mdblPropertytaxesTotal = ((mdblPurchasePrice * 0.025) / 12)
lblPropertyTaxesTotal.Text = mdblPropertytaxesTotal.ToString("c")
'determine insurance
mdblInsuranceTotal = ((mdblPurchasePrice * 0.008) / 12)
lblInsuranceTotal.Text = mdblInsuranceTotal.ToString("c")
'determine monthly payment
mdblMonthlyPaymentTotal = mdblPrincipalInterestTotal + mdblPropertytaxesTotal + mdblInsuranceTotal
lblMonthlyPaymentTotal.Text = mdblMonthlyPaymentTotal.ToString("c")
End Sub
Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
'Close the Application
Me.Close()
End Sub
Private Sub btnClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClear.Click
'Clears the labels and input boxes and puts focus back on purchase price box
txtPurchasePrice.Focus()
txtPurchasePrice.Text = ""
txtInterestRate.Text = ""
lblDownPaymentTotal.Text = ""
lblClosingCostTotal.Text = ""
lblCashtoCloseTotal.Text = ""
lblPrincipalInterestTotal.Text = ""
lblPropertyTaxesTotal.Text = ""
lblInsuranceTotal.Text = ""
lblMonthlyPaymentTotal.Text = ""
End Sub
End Class
Ok, the problem that I'm having is this:
When I enter $1000 for PurchasePrice and 7% for Interest rate the PrincipalInterest returns $70.00 instead of the correct answer which is $466.67
Am I missing something but I thought the PMT function was supposed to take care of all the computations.
I've tried both formats:
Literal: PMT(.07, 360, 1000, 0)
and
Variable mdblPrincipalInterestTotal = Financial.Pmt(mdblInterestRate, mdblperiod, mdblPurchasePrice, 0)
and neither one is returning the correct value.
I'm using VB .NET 2005.
Thanks,
Zuelin