Loan Calculator, PMT problems
Loan Calculator, PMT problems
Loan Calculator, PMT problems
Loan Calculator, PMT problems
Loan Calculator, PMT problems
Loan Calculator, PMT problems Loan Calculator, PMT problems Loan Calculator, PMT problems Loan Calculator, PMT problems Loan Calculator, PMT problems Loan Calculator, PMT problems Loan Calculator, PMT problems Loan Calculator, PMT problems
Loan Calculator, PMT problems Loan Calculator, PMT problems
Loan Calculator, PMT problems
Go Back  Xtreme Visual Basic Talk > > > Loan Calculator, PMT problems


Reply
 
Thread Tools Display Modes
  #1  
Old 12-03-2014, 08:58 PM
FireSlade FireSlade is offline
Newcomer
 
Join Date: Sep 2014
Posts: 3
Default Loan Calculator, PMT problems


Trying to code a loan calculator that uses hscroll bars for the years and interest rate. When I hit the calculate button, I get an exception and my PMT calculation gets highlighted. Don't have much experience with this and the text for dealing with this that I am using is very vague on the topic. I just want to know where I coded wrong. Thanks for any and all help.

Error Message:

System.ArgumentException was unhandled
HResult=-2147024809
Message=Argument 'NPer' is not a valid value.
Source=Microsoft.VisualBasic
StackTrace:
at Microsoft.VisualBasic.Financial.PMT_Internal(Double Rate, Double NPer, Double PV, Double FV, DueDate Due)
at Microsoft.VisualBasic.Financial.Pmt(Double Rate, Double NPer, Double PV, Double FV, DueDate Due)

My code:
Code:
Option Strict On

Public Class LoanForm
    'Declare Module-Level Variables

    Private Const RateScale As Double = 0.5

    Private Sub LoanForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Set Initial Values

        YearsTextBox.Text = "15"
        RateTextBox.Text = "10.0%"

    End Sub

    Private Sub YearsScrollBar_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles YearsScrollBar.Scroll
        'Calculate and Display Current Amounts and Add to Totals.

        Dim YearsDouble As Double

        'Set Initial Values

        YearsDouble = YearsScrollBar.Value

        'Format and Display Results

        YearsTextBox.Text = YearsDouble.ToString

    End Sub

    Private Sub RateScrollBar_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles RateScrollBar.Scroll
        'Calculate and Display Current Amounts and Add to Totals.

        Dim RateDouble As Double

        RateDouble = RateScrollBar.Value * RateScale * 0.01

        'Format and Display

        RateTextBox.Text = RateDouble.ToString("P1")

    End Sub

    Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click
        'Clears input Text and Resets Form to Default State

        LoanAmountTextBox.Clear()
        YearsTextBox.Text = "15"
        RateTextBox.Text = "10.0%"
        MonthlyPaymentTextBox.Clear()
        TotalTextBox.Clear()

    End Sub

    Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
        'Exits the Application

        Me.Close()
    End Sub

    Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click
        'Calculate and Display Current Amounts and Add to Totals

        Dim RateDouble, YearsDouble, MonthlyPaymentDouble, TotalPaymentDouble, LoanAmountDouble, MonthsDouble, MonthlyRateDouble As Double

        Try
            MonthlyRateDouble = RateDouble / 12
            MonthsDouble = YearsDouble * 12
            LoanAmountDouble = Double.Parse(LoanAmountTextBox.Text)
            MonthlyPaymentDouble = -Pmt(MonthlyRateDouble, MonthsDouble, LoanAmountDouble)
            MonthlyPaymentTextBox.Text = MonthlyPaymentDouble.ToString("C")
            TotalPaymentDouble = MonthlyPaymentDouble * MonthsDouble
            TotalTextBox.Text = TotalPaymentDouble.ToString("C")

        Catch InputException As FormatException
            MessageBox.Show("Invalid Input.", "Data Entry Error",
                            MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub

Last edited by Flyguy; 12-04-2014 at 02:00 AM. Reason: Added [code][/code] tags
Reply With Quote
  #2  
Old 12-04-2014, 10:37 AM
PlausiblyDamp's Avatar
PlausiblyDampLoan Calculator, PMT problems PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

If you add a breakpoint on the line
Code:
MonthlyPaymentDouble = -Pmt(MonthlyRateDouble, MonthsDouble, LoanAmountDouble)
what are the values of the variables you are passing in? From the code it looks as though some of them might be 0 rather than whatever values you are expecting.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
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
Loan Calculator, PMT problems
Loan Calculator, PMT problems
Loan Calculator, PMT problems Loan Calculator, PMT problems
Loan Calculator, PMT problems
Loan Calculator, PMT problems
Loan Calculator, PMT problems Loan Calculator, PMT problems Loan Calculator, PMT problems Loan Calculator, PMT problems Loan Calculator, PMT problems Loan Calculator, PMT problems Loan Calculator, PMT problems
Loan Calculator, PMT problems
Loan Calculator, PMT problems
 
Loan Calculator, PMT problems
Loan Calculator, PMT problems
 
-->