Arrays Visual Basic:索引超出了数组的边界
我试图让这个VisualBasic程序在多维数组中存储值。我看到的所有其他错误都是由于索引超出了数组的边界,这是由于数组是在变量之前声明的,但是我很确定我声明的位置是正确的。有人知道怎么了吗Arrays Visual Basic:索引超出了数组的边界,arrays,vb.net,visual-studio-2010,Arrays,Vb.net,Visual Studio 2010,我试图让这个VisualBasic程序在多维数组中存储值。我看到的所有其他错误都是由于索引超出了数组的边界,这是由于数组是在变量之前声明的,但是我很确定我声明的位置是正确的。有人知道怎么了吗 Randomize() Dim roll As Integer = 0 Dim player As Integer Dim index As Integer Console.Writeline("Enter the number of players: ")
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
使用
roll=0
对players()
进行尺寸标注,然后循环直到roll=5
。这显然超出了数组的范围。您使用roll=0
对players()
进行尺寸标注,然后循环直到roll=5
。这显然超出了数组的范围。我要添加一个新变量-尝试将代码更改为:
Dim MaxRolls as integer
MaxRolls = 5
然后:
这应该会解决它我会添加一个新变量-尝试将代码更改为:
Dim MaxRolls as integer
MaxRolls = 5
然后:
这应该可以解决它了Oops,这是一个非常明显的错误,谢谢。(最好在7分钟内回答)。哦,那是一个非常明显的错误,谢谢。(最好在7分钟内回答)。