Solved

Format Exception was Unhandled

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

738 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