Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact
A1VBCode Forums
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )

Home » .NET Programming » Visual Basic .NET » mortgage calculator program mortgage calculator programExpand / Collapse
Posted 5/2/2005 8:53:11 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 5/3/2005 7:13:00 PM
Posts: 1, Visits: 1

I am working on a mortgage calculator program in  I have created it and can input loan amount, interest rate, term and get what the monthly payment will be.  The next thing I need to do is allow it to list the new loan amount and interest paid for each period of the term of the loan.  I think I need to use a loop and since it will display 15 years of payments and results I need it to display partial list, hesitate, then display more of the list.  I have placed a list box and am trying to get the result for the first monthly payment to subtract from the total loan amount and then display the new amount in the list box. I need help in writing the loop that will allow this to occur.  Can someone help me out with this?  Here is where I am now

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click

'Calculate the Monthly Payment'

Dim dblAmount As Double

Dim dblMonthlyRate As Double

Dim dblMonths As Double

Dim 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'

dblMonthlyPayment = -Pmt(dblMonthlyRate / 12, dblMonths * 12, dblAmount)

'Format answer'

txtMonthlyPayment.Text = FormatCurrency(dblMonthlyPayment)

'Results for listbox should be new loan balance and interest rate'

'Result should be from Loan Amount minus result in Payment field'

'Dim dblLoanInterest As Double

'Dim i As Integer

'Dim NewLine As String

'dblLoanInterest = CDbl(lstLoanInterest.Text)

'dblLoanInterest = dblAmount - dblMonthlyPayment



End Sub


Post #11120
Posted 5/3/2005 12:45:08 AM
Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: 3/13/2006 2:34:13 AM
Posts: 794, Visits: 338
Like I already answered at

   Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.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)
            lstLoanInterest.Items.Add(FormatCurrency(TotPrincipal).PadRight(25) & FormatCurrency(iPayment).PadRight(25) & FormatCurrency(dblBalance).PadLeft(25))
            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)
        lstLoanInterest.Items.Add(" _______________________________" )
        lstLoanInterest.Items.Add(" Total interest paid: "  & FormatCurrency(TotInt))
        lstLoanInterest.Items.Add(" _______________________________" )
        lstLoanInterest.Items.Add(" Total Paid after: "  & mPayments & "  Payments = "  & FormatCurrency(TotInt + TotPrincipal))
        lstLoanInterest.Items.Add(" _______________________________" )
        lstLoanInterest.Items.Add(" Last Payment is an interest payment of course, and it is "  & FormatCurrency(iPayment))
        ’Format answer'
        dblMonthlyPayment = CDbl(iPayment + pPayment)
        txtMonthlyPayment.Text = FormatCurrency(dblMonthlyPayment)
    End Sub

I'm no accountant, so use at own risk! <---my disclaimer

Post #11140
Posted 3/29/2010 1:45:51 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 3/29/2010 1:37:53 PM
Posts: 1, Visits: 1
Hello Im very interested to see if I can get this mortgage payment calculator code working in access. I had attempted to make it as a private sub, but there are several lines that show up red in vba window in access. Before I post what lines they are, I would like to know if indeed this code is for access or is this (sorry I do not know difference)

anyway I have been trying to make a repayment calculator in access to link with existing DB, but to no avail. I could link my access DB with a mortgage repayment calc in Excell, however I really want to just keep within access for this project.

Hope you can point me in the right direction

many thanks


vba "learn it as i build"

Post #29080
« Prev Topic | Next Topic »

Reading This TopicExpand / Collapse
Active Users: 2 (2 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Admin, Mod, Mark, Keithuk

PermissionsExpand / Collapse

All times are GMT -5:00, Time now is 5:16pm