Solved

Format Exception was Unhandled

Posted on 2010-09-12
2
301 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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

777 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