Link to home
Start Free TrialLog in
Avatar of RobJanine
RobJanine

asked on

Format Exception was Unhandled

I am getting the following error in the below code
Format Exception was unhandled
Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

The error is in the line of code starting lstOutput in Sub FinancialCharges.
Can someone please tell me what I am doing wrong?

Public Class frmCreditCardAccounts

    Private Sub btnDisplaySummary_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplaySummary.Click
        Dim AccountNumber As String, PastDueAmt, Payments, Purchases As Double
        Dim sr As IO.StreamReader = IO.File.OpenText("3-PP-3.TXT")
        Dim fmtStr As String = "{0,-30}{1,8}    {2,8}   {3,8}   {4,8}   {5,8}"
        lstOutput.Items.Clear()
        lstOutput.Items.Add(String.Format(fmtStr, "Account Number", "Past Due Amount", "Payments", "Purchases", "Financial Charges", "Current Amount Due"))
        AccountNumber = sr.ReadLine
        PastDueAmt = CDbl(sr.ReadLine)
        Payments = CDbl(sr.ReadLine)
        Purchases = CDbl(sr.ReadLine)
        CalcFinancialCharges(AccountNumber, PastDueAmt, Payments, Purchases)
        AccountNumber = sr.ReadLine
        PastDueAmt = CDbl(sr.ReadLine)
        Payments = CDbl(sr.ReadLine)
        Purchases = CDbl(sr.ReadLine)
        CalcFinancialCharges(AccountNumber, PastDueAmt, Payments, Purchases)
        sr.Close()


    End Sub


    Sub CalcFinancialCharges(ByVal AccountNumber As String, ByVal PastDueAmt As Double, ByVal Payments As Double, ByVal Purchases As Double)

        Dim FinancialCharges As Integer
        Dim fmtStr As String = "{0,-30}{1,4}    {2,4}   {3,8}   {4,8}   {5,8}"
        FinancialCharges = (PastDueAmt - Payments) * 0.015
        lstOutput.Items.Add(String.Format(fmtStr, AccountNumber, PastDueAmt, Payments, Purchases, FormatCurrency(FinancialCharges, 2)))

    End Sub

    Sub CalcCurrentAmtDue(ByVal AccountNumber As String, ByVal PastDueAmt As Double, ByVal Payments As Double, ByVal Purchases As Double, ByVal FinancialCharges As Double)

        Dim CurrentAmtDue As Integer
        Dim fmtStr As String = "{0,-30}{1,8}    {2,8}   {3,8}   {4,8}   {5,8}"
        CurrentAmtDue = PastDueAmt - Payments + Purchases + FinancialCharges
        lstOutput.Items.Add(String.Format(fmtStr, AccountNumber, PastDueAmt, Payments, Purchases, FormatCurrency(FinancialCharges, 2)))

    End Sub
End Class
ASKER CERTIFIED SOLUTION
Avatar of appari
appari
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or may be you missed printing CurrentAmtDue ,

Sub CalcCurrentAmtDue(ByVal AccountNumber As String, ByVal PastDueAmt As Double, ByVal Payments As Double, ByVal Purchases As Double, ByVal FinancialCharges As Double)

        Dim CurrentAmtDue As Integer
        Dim fmtStr As String = "{0,-30}{1,8}    {2,8}   {3,8}   {4,8}   {5,8}"
        CurrentAmtDue = PastDueAmt - Payments + Purchases + FinancialCharges
        lstOutput.Items.Add(String.Format(fmtStr, AccountNumber, PastDueAmt, Payments, Purchases, FormatCurrency(FinancialCharges, 2), CurrentAmtDue ))

    End Sub