Solved

Help Figuring Out Calculating Payment with VB

Posted on 2013-05-10
4
246 Views
Last Modified: 2013-05-13
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

Open in new window

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
Comment
Question by:aclaus225
4 Comments
 
LVL 12

Expert Comment

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

Open in new window


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

Expert Comment

by:mcsween
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)

Open in new window

0
 

Author Comment

by:aclaus225
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 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 39162189
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

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

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

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now