Solved

Help Figuring Out Calculating Payment with VB

Posted on 2013-05-10
257 Views
I am trying to program a mortgage type calculator with Visual Basic and can't quite figure out the code.
``````    Private Sub calcbutton_Click(sender As System.Object, e As System.EventArgs) Handles calcbutton.Click
'The car price should appear in terms of dollars and cents.
Dim carprice As Double
'The APR needs two percentage points
Dim interestrate As Double
'Money down should be dollars and cents
Dim moneydown As Double
'Dim loan term As Double
Dim loanterm As Double
'Dim Payment as Double
Dim payment As Double
Dim monthlyinterest As Double
Dim months As Double
Dim loanamount As Double

'Declare where the values are coming from
carprice = Val(Carpricetext.Text)
interestrate = Val(IRTextbox.Text)
moneydown = Val(Dwnpymnttext.Text)
loanterm = Val(LnTrmList.SelectedValue)
loanamount = (carprice - moneydown)

Do While loanterm <= 5
monthlyinterest = (interestrate / 100) / 12
months = 12 * loanterm

'calculate payments - rate * month = monthly payments
payment = _
Pmt(monthlyinterest, months, -loanamount)

'displays results
paymenttxt.Text = payment

Loop
End Sub
``````
When I debug this:
payment = _
Pmt(monthlyinterest, months, -loanamount)
This tells me Argument 'NPer' is not a valid value.

Any ideas on what I need to do?
0
Question by:aclaus225
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• Learn & ask questions

LVL 12

Expert Comment

ID: 39156508
It looks like somewhere along the line, months ends up = 0.
Just in case, you might try:
``````loanterm = CDbl(LnTrmList.SelectedValue)
``````

You can also break on line 34, look at the values of the arguments and backtrack from there.
0

LVL 22

Expert Comment

ID: 39156525
NPer is the second argument in the Pmt function.  It's complaining it doesn't like the value for month.

Add the following line after months = 12 * loanterm to see what is actually being set for months.  You may have to use the CInt function to cast it to an integer.
``````MsgBox(months)
``````
0

Author Comment

ID: 39156602
mcsween,

The message box popped up "0" so would that indicate the the program is not reading what is in the list box LnTrmList.SelectedValue?
0

LVL 86

Accepted Solution

Mike Tomlinson earned 500 total points
ID: 39162189
0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Time out only from one specific computer client 15 53
Read top line from CSV file 14 59
vb.net code 9 28
VB.Net CLR Assembly type Datatable into SQL 8 21
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Introduction to Processes
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Suggested Courses
Course of the Month4 days, 14 hours left to enroll

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.