Solved

Format Exception was Unhandled

Posted on 2010-09-12
2
296 Views
Last Modified: 2013-11-27
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
0
Comment
Question by:RobJanine
  • 2
2 Comments
 
LVL 39

Accepted Solution

by:
appari earned 500 total points
ID: 33659048
your format string has total 6 parameters but in your string.format call you are using only 5 parameters. either change the format string or supply the missing value in your string.format(...

something like this,

    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}"
        Dim fmtStr As String = "{0,-30}{1,8}    {2,8}   {3,8}   {4,8} "  '****** removed  {5,8}"

        CurrentAmtDue = PastDueAmt - Payments + Purchases + FinancialCharges
        lstOutput.Items.Add(String.Format(fmtStr, AccountNumber, PastDueAmt, Payments, Purchases, FormatCurrency(FinancialCharges, 2)))

    End Sub
0
 
LVL 39

Expert Comment

by:appari
ID: 33659054
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
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

746 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

13 Experts available now in Live!

Get 1:1 Help Now