Solved

Format Exception was Unhandled

Posted on 2010-09-12
2
305 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

756 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