I’m trying to get this Visual Basic program to store values in a multi-dimensional array. All other errors I’ve seen due to an index being outside bounds of array have been due to the fact that the array is declared before the variable, but I’m pretty sure I declared mine in the right place. Can anyone see what’s wrong?
Randomize()
Dim roll As Integer = 0
Dim player As Integer
Dim index As Integer
Console.Writeline("Enter the number of players: ")
index = Convert.ToInt32(Console.Readline)
player = index - 1
Dim players(player,roll) As Integer
Do Until index = 0
Do Until roll = 5
players(player,roll) = CInt(Int((6 * Rnd()) + 1))
roll +=1
Loop
player -=1
Loop
You dimension
players()withroll=0, but then loop untilroll=5. That’s obviously outside the bounds of your array.