Results 1 to 2 of 2

Thread: System.IndexOutOfRangeException thrown.

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2011
    Posts
    2

    System.IndexOutOfRangeException thrown.

    Hi all, I'm still a newbie to programming and in school we are working with arrays.
    We received a program that needs to have modifications done to it and I don't understand why the "89000" amount is outside the array bounds. It is a console app. that calculates amortization.

    Code:
     Sub Main()
            'Testing Start When testing comment the line below and
            ' uncomment Dim s(3) below
            Dim s() As String = System.Environment.GetCommandLineArgs()
            'Dim s(3) As String
            'Testing End -
    
            Dim dblLoanAmount As Double
            Dim intYears As Integer
            Dim dblInterestRate As Double
            'Testing Start - When testing uncomment the 3 lines below
            s(1) = "89000"
            s(2) = "30"
            s(3) = ".04"
            'Testing End - 
    
            If s.Length = 4 Then
                If ValidateParms(s(1), s(2), s(3)) = True Then
                    'Continue processing Amort Schedule
                    'Explicitly Convert inputs to numerics to be passed
                    ' to AmortSched below
    
                    'YOUR CODE HERE
    
                    AmortSched(dblLoanAmount, intYears, dblInterestRate)
                Else
                    Console.WriteLine("Parameters not valid")
                    Console.WriteLine("Amount " & s(1))
                    Console.WriteLine("Periods " & s(2))
                    Console.WriteLine("Annual Rate " & s(3))
                End If
            Else
                Console.WriteLine("Missing parameters")
            End If
    
            'Keep command line window open until user presses ENTER
            Console.ReadLine()
        End Sub
    How can I change the bounds of the array? Thanks!

    -radioactivedrummer

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: System.IndexOutOfRangeException thrown.

    It's nothing to do with the "89000". That's not an index. That's a value that you're trying to assign to an element at index 1 in the array and it's that index that is invalid.

    I think you need to read the comments in that code a bit more closely.
    Code:
            'Testing Start When testing comment the line below and
            ' uncomment Dim s(3) below
            Dim s() As String = System.Environment.GetCommandLineArgs()
            'Dim s(3) As String
            'Testing End -
    According to that you are NOT testing.
    Code:
            'Testing Start - When testing uncomment the 3 lines below
            s(1) = "89000"
            s(2) = "30"
            s(3) = ".04"
            'Testing End -
    According to that you ARE testing. You need to comment and uncomment the correct lines as instructed depending on whether you are testing or not.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width