Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > help with using the "pmt function"


Reply
 
Thread Tools Display Modes
  #1  
Old 01-13-2003, 07:05 PM
Andy H
Guest
 
Posts: n/a
Default help with using the "pmt function"


I'm writing a program to figure monthly payments. I have to use the pmt function. I keep getting a run time error 5. Invalid procedure call or argument. When I hit debug it points to this line.
Code:
Payment = Pmt(APR / 12, TotPmts, -PVal)
Any help would be appreciated.
Here is all of my code for this program.
Code:
Option Explicit Private Sub cmdCalc_Click() Dim PVal As Double, APR As Double Dim TotPmts As Double, Payment As Double Select Case lstInterest.ListIndex Case 0 APR = 7 Case 1 APR = 7.25 Case 2 APR = 7.5 Case 3 APR = 7.75 Case 4 APR = 8 Case 5 APR = 8.25 Case 6 APR = 8.5 Case 7 APR = 8.75 Case 8 APR = 9 Case 9 APR = 9.25 Case 10 APR = 9.5 Case 11 APR = 9.75 Case 12 APR = 10 Case 13 APR = 10.25 Case 14 APR = 10.5 Case 15 APR = 10.75 Case 16 APR = 11 Case 17 APR = 11.25 Case 18 APR = 11.5 Case 19 APR = 11.75 Case 20 APR = 12 End Select Payment = 0 TotPmts = 12 PVal = Val(txtPrincipal.Text) If APR > 1 Then APR = APR / 100 ElseIf optTerm(0).Value = True Then TotPmts = 24 ElseIf optTerm(1).Value = True Then TotPmts = 36 ElseIf optTerm(2).Value = True Then TotPmts = 48 ElseIf optTerm(3).Value = True Then TotPmts = 60 End If Payment = -Pmt(APR / 12, TotPmts, PVal) lblPayment.Caption = Payment End Sub Private Sub Form_Load() frmMthlyPay.Left = (Screen.Width - frmMthlyPay.Width) / 2 frmMthlyPay.Top = (Screen.Height - frmMthlyPay.Height) / 2 lstInterest.AddItem "7%" lstInterest.AddItem "7.25%" lstInterest.AddItem "7.50%" lstInterest.AddItem "7.75%" lstInterest.AddItem "8%" lstInterest.AddItem "8.25%" lstInterest.AddItem "8.50%" lstInterest.AddItem "8.75%" lstInterest.AddItem "9%" lstInterest.AddItem "9.25%" lstInterest.AddItem "9.50%" lstInterest.AddItem "9.75%" lstInterest.AddItem "10%" lstInterest.AddItem "10.25%" lstInterest.AddItem "10.50%" lstInterest.AddItem "10.75%" lstInterest.AddItem "11%" lstInterest.AddItem "11.25%" lstInterest.AddItem "11.50%" lstInterest.AddItem "11.75%" lstInterest.AddItem "12%" End Sub Private Sub mnuFileExit_Click() Unload Me End Sub Private Sub mnuFilePrint_Click() PrintForm End Sub Private Sub mnuFormatBackground_Click() dlgCommon.Color = frmMthlyPay.BackColor dlgCommon.ShowColor frmMthlyPay.BackColor = dlgCommon.Color End Sub Private Sub mnuFormatFont_Click() dlgCommon.FontName = lblPayment.FontName dlgCommon.FontBold = lblPayment.FontBold dlgCommon.FontItalic = lblPayment.FontItalic dlgCommon.FontSize = lblPayment.FontSize dlgCommon.ShowFont lblPayment.FontName = dlgCommon.FontName lblPayment.FontBold = dlgCommon.FontBold lblPayment.FontItalic = dlgCommon.FontItalic lblPayment.FontSize = dlgCommon.FontSize End Sub Private Sub mnuFormatInfo_Click() dlgCommon.Color = fraInfo.BackColor dlgCommon.ShowColor fraInfo.BackColor = dlgCommon.Color End Sub

Last edited by Andy H; 01-13-2003 at 08:28 PM.
Reply With Quote
  #2  
Old 01-13-2003, 07:47 PM
Iceplug's Avatar
Iceplug Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
Default

Your TotPmts value is probably zero. Perhaps you should set it to 12 instead of 0 before the PVal = Val(txtPrincipal.Text)

Also, you can set the If blocks like
Code:
If ... Then
  ...
ElseIf ... Then
  ...
End If

instead of
If ... Then
  ...
Else
  If ... Then
    ...
  End If
End If
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #3  
Old 01-13-2003, 08:11 PM
Andy H
Guest
 
Posts: n/a
Default

Thanks Iceplug! that fixed it. Is using the select case like above the correct way to get the interest from the list box?

Last edited by Andy H; 01-13-2003 at 08:23 PM.
Reply With Quote
  #4  
Old 01-14-2003, 06:54 AM
Iceplug's Avatar
Iceplug Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
Default

Well, there's no "correct" way of getting the interest, just as long as it works. However, a Select Case would be OK in situations like this... however, you could convert this into an 'expression' to get the APR from the ListIndex (where both are numbers and both increase in a linear fashion i.e. 7,7.25,7.5 going up by 0.25)
such as the expression APR = 0.25 * lstInterest.ListIndex + 7.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->