3 Replies - 303 Views - Last Post: 08 May 2021 - 11:14 AM Rate Topic: -----

#1 adekkagura   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-May 21

System.ArgumentException: 'Argument 'NPer' is not a valid

Posted 08 May 2021 - 08:55 AM

HI. I am student. I have problem with my assignment task. I able to debug but when I click calculate button, (System.ArgumentException: 'Argument 'NPer' is not a valid value.') pop up. can someone help me?

this is my coding.
Public Class Form1

    Const dblMonths_Year As Double = 12
    Const dblNew_Rate As Double = 0.05
    Const dblUsed_Rate As Double = 0.08
    Dim dblAnnualRate As Double = dblNew_Rate

    Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click


        Dim dblVehicleCost As Double
        Dim dblDownPayment As Double
        Dim dblMonths As Double
        Dim dblLoan As Double
        Dim dblMonthlyPayment As Double
        Dim dblInterest As Double
        Dim dblPrincipal As Double
        Dim intCount As Integer
        Dim strOut As String
        Dim blnInputOK As Boolean = True



        If blnInputOK = True Then
            dblLoan = dblVehicleCost - dblDownPayment
            dblMonthlyPayment = Pmt(dblAnnualRate / dblMonths_Year, dblMonths, -dblLoan)
            lstOutput.Items.Clear()

            For intCount = 1 To dblMonths
                dblInterest = IPmt(dblAnnualRate / dblMonths_Year, intCount, dblMonths, -dblLoan)
                dblPrincipal = PPmt(dblAnnualRate / dblMonths_Year, intCount, dblMonths, -dblLoan)
                strOut = "Month" & intCount.ToString("d2")
                strOut &= ": payment =" & dblMonthlyPayment.ToString("n2")
                strOut &= ", interest =" & dblInterest.ToString("n2")
                strOut &= ", principal =" & dblPrincipal.ToString("n2")
                lstOutput.Items.Add(strOut)

            Next

        End If


    End Sub

    Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
        radNew.Checked = True
        dblAnnualRate = dblNew_Rate
        lblAnualRate.Text = dblNew_Rate.ToString("p")
        txtCost.Clear()
        txtDownPayment.Clear()
        txtMonths.Clear()
        lstOutput.Items.Clear()
        txtCost.Focus()

    End Sub

    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
        Close()
    End Sub

    Private Sub radNew_CheckedChanged(sender As Object, e As EventArgs) Handles radNew.CheckedChanged
        If radNew.Checked = True Then
            dblAnnualRate = dblNew_Rate
            lblAnualRate.Text = dblNew_Rate.ToString("p")
            lstOutput.Items.Clear()

        End If
    End Sub

    Private Sub radUsed_CheckedChanged(sender As Object, e As EventArgs) Handles radUsed.CheckedChanged
        If radUsed.Checked = True Then
            dblAnnualRate = dblUsed_Rate
            lblAnualRate.Text = dblUsed_Rate.ToString("p")
            lstOutput.Items.Clear()

        End If
    End Sub
End Class

:code:

This post has been edited by modi123_1: 08 May 2021 - 10:30 AM
Reason for edit:: In the future please use the [code] tag button in the editor


Is This A Good Question/Topic? 0
  • +

Replies To: System.ArgumentException: 'Argument 'NPer' is not a valid

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 16253
  • View blog
  • Posts: 64,719
  • Joined: 12-June 08

Re: System.ArgumentException: 'Argument 'NPer' is not a valid

Posted 08 May 2021 - 10:30 AM

What line is that happening on?
Was This Post Helpful? 0
  • +
  • -

#3 adekkagura   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-May 21

Re: System.ArgumentException: 'Argument 'NPer' is not a valid

Posted 08 May 2021 - 11:02 AM

View Postmodi123_1, on 08 May 2021 - 10:30 AM, said:

What line is that happening on?



line 26. Thankyou for your respon
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 16253
  • View blog
  • Posts: 64,719
  • Joined: 12-June 08

Re: System.ArgumentException: 'Argument 'NPer' is not a valid

Posted 08 May 2021 - 11:14 AM

So this line?

26	            dblMonthlyPayment = Pmt(dblAnnualRate / dblMonths_Year, dblMonths, -dblLoan)


I would put a breakpoint there and see what the values are in those variables. Seems there is something incorrect in there, in that function, or what not.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1