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
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.