Link to home
Start Free TrialLog in
Avatar of slammer14
slammer14

asked on

HELP HELP CALCULAYE PAYMENT PER MONTH

AzraSound is it possible to email you project to understand??



WE are currently having troubles with this code.
Answer comes up wrong.

Need Help debugging PMT function.

URGENT Need Answer soon.

// Here is code used

Option Explicit
Dim intTval As Integer

Private Sub cmdCalc_Click()

    Dim dblPval As Double, dblIval As Double, dblPayment As Double
    'call function to determine # of payments
     
    dblPval = txtPrincipal.Text
    dblIval = Val(lstInterest().Text) / 10
     
     If optTerm(0).Value = True Then
        intTval = 24
    End If
       
    If optTerm(1).Value = True Then
        intTval = 36
    End If
       
    If optTerm(2).Value = True Then
        intTval = 48
   
    Else
        intTval = 60
       
    End If
   
   
            'formula for the payment total
   ' dblPayment = Pmt(dblIval / 12, intTval, dblPval)
   'dblPayment = Pmt(dblIval / 12, dblPval, intTval)
    lblPayment.Caption = dblPayment
   
    txtPrincipal.SelStart = 0
    txtPrincipal.SelLength = Len(txtPrincipal.Text)
   
   
   
   
End Sub

Private Sub Form_Load()
    frmMthlyPay.Left = (Screen.Width - frmMthlyPay.Width) / 2
    frmMthlyPay.Top = (Screen.Height - frmMthlyPay.Height) / 2
   
   
txtPrincipal.SelStart = 0
    txtPrincipal.SelLength = Len(txtPrincipal.Text)
    lstInterest.AddItem "7.00"
    lstInterest.AddItem "7.25"
    lstInterest.AddItem "7.50"
    lstInterest.AddItem "7.75"
    lstInterest.AddItem "8.00"
    lstInterest.AddItem "8.25"
    lstInterest.AddItem "8.50"
    lstInterest.AddItem "8.75"
    lstInterest.AddItem "9.00"
    lstInterest.AddItem "9.25"
    lstInterest.AddItem "9.50"
    lstInterest.AddItem "9.75"
    lstInterest.AddItem "10.00"
    lstInterest.AddItem "10.25"
    lstInterest.AddItem "10.50"
    lstInterest.AddItem "10.75"
    lstInterest.AddItem "11.00"
    lstInterest.AddItem "11.25"
    lstInterest.AddItem "11.50"
    lstInterest.AddItem "11.75"
    lstInterest.AddItem "12.00"
   
    lstInterest.ListIndex = 14      ' assign default values
    optTerm(2).Value = True
   
   
End Sub
 


Private Sub mnuFileExit_Click()

      Unload frmMthlyPay
     
End Sub


Private Sub mnuFilePrint_Click()
    cmdCalc.Visible = False
    PrintForm
    cmdCalc.Visible = True
   
End Sub


Private Sub mnuFormatBackground_Click()

    dlgMonth.Flags = cdlCCRGBInit
    dlgMonth.Color = txtPrincipal.ForeColor
    dlgMonth.ShowColor
    frmMthlyPay.BackColor = dlgMonth.Color
   
   
End Sub


Private Sub mnuFormatFont_Click()
    dlgMonth.Flags = cdlCFScreenFonts
   
    dlgMonth.FontName = lblPayment.FontName
    dlgMonth.FontBold = lblPayment.FontBold
    dlgMonth.FontItalic = lblPayment.FontItalic
    dlgMonth.FontSize = lblPayment.FontSize
   
    dlgMonth.ShowFont
   
    lblPayment.FontName = dlgMonth.FontName
    lblPayment.FontBold = dlgMonth.FontBold
    lblPayment.FontItalic = dlgMonth.FontItalic
    lblPayment.FontSize = dlgMonth.FontSize
   
End Sub

Private Sub mnuFormatInfo_Click()

    dlgMonth.Flags = cdlCCRGBInit
    dlgMonth.Color = txtPrincipal.ForeColor
    dlgMonth.ShowColor
    fraInfo.BackColor = dlgMonth.Color
   
End Sub



Thanks Slammer 14


Avatar of AzraSound
AzraSound
Flag of United States of America image

Maybe you need to use the Val function when doing dblPval = txtPrincipal.Text
   
Also, why no index specified in dblIval = Val(lstInterest().Text) / 10  ??
Avatar of slammer14
slammer14

ASKER

Edited text of question.
you can email me if youd like
AzraSound@aol.com
Here is a function to calculate Total Payment Amount. The syntax to use it is (rounding the result to 2 decimal positions)..

Dim curReturnValue as Currency
curReturnValue = Round(xTotalPaymentAmount(curPrinciple, dblAnnualInterestRate, intMonths), 2)

Eg.

curReturnValue = Round(xTotalPaymentAmount(10000, 7.5, 48), 2)

<----- Code Begin ----->

Private Function xTotalPaymentAmount _
(ByVal curPrinciple As Currency, dblAnnualInterestRate As Double, intMonths As Integer) _
As Currency

    xTotalPaymentAmount = curPrinciple _
        * ((1 + (dblAnnualInterestRate / 100)) _
        ^ (CDbl(intMonths) / 12))
   
End Function

<----- Code End ----->
ASKER CERTIFIED SOLUTION
Avatar of AzraSound
AzraSound
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Azrasound:
Although you have contributed greatly, this puppy is hardly done.. hence a comment may have been a little more appropriate.. <wink>.  Yes.. this is a loan calculator.. but no, dblPval should not be negative as it is customary to show all numbers in there positive form.. <smile>.

------------------------------------

Yup.. he's got his share of bugz..  He's dividing his Interest rate by 10, rather than 100.. he probably should be using comboboxes rather than listboxes, so that the user can enter Interest Rates and / or Payment periods not listed.. his PMT function is compounding Monthly, rather than annually (but I suppose that may be ok).

The raw empiricism for calculating Total Payments based on an APR (Annual Percentage Rate) is in the function I included above. It accepts the annual percentage rate as most people key them ie. 7.50%. If you want the Monthly Payment amount, just divide the Total Payment Amount calculated by the number of Months.. <smile>.
actually in the way that the Pmt function is structured, the dblPval does need to be negative in accordance with the optional paramter 'fv' that when left out defaults to 0.  fv tells us what the final amount should be after the last payment, and this being a loan, the values being added need to equal 0, thus requiring an initial value to be negative.
wsh2,
I think the confusion here is the fact that you are creating your own function and they are using the built in Pmt function   =)
Adjusted points from 50 to 100
Personable and Informative help..!
I thought it almost got too personal after that Victoria comment...but thats neither here nor there  =oP   take care