Index Out Of Range Exception
Hello Everyone:
I keep getting the error message “Index out of range exception” when I run the following code.
XX Code:
GN3 = (Loops * 5)
For a = 1 To Loops
For b = 1 To GN3
R1 = Seeds1(Counter1)
Randomize()
R2 = CInt(Int((56 * Rnd(R1)) + 1))
Counter1 += 1
MessageBox.Show(R1 & " " & Counter1 & " " & b & " " & GN3)
Next b
Next a
The message box conforms that the last entry in the array has been reached. And that Counter1 and b both start at 1 and go to 2845. And that GN3 is also 2845 all of the time. What am I doing wrong?
Thanks
Art W.
Re: Index Out Of Range Exception
.NET arrays and collections are zero-based, i.e. an array with a Length on N has elements at indexes 0 to (N-1).
Also, if you're going to use Randomize and Rnd then don't call Randomize over and over. You're supposed to call it once and once only. That said, don't use Randomize and Rnd anyway. This is VB.NET, not VB6, so use the Random class.