這只是我的一部分代碼,但它引起了我的問題。該代碼的預期目的是獲取用戶輸入並將其作爲數組的大小。然而,它給我的錯誤「索引是在數組的界限之外」,無論我輸入什麼值。索引超出了Visual Basic中數組的範圍
下面是代碼:
Option Explicit On
Option Strict On
Imports System
Module numbers
Sub Main()
'index decides number of candidates.
Dim index as integer
Dim candidate(index) as integer
Console.Write("Please enter the number of candidates in the election: ")
index=Convert.toInt32(Console.Readline())
Do Until candidate(index) >= 0
Console.Write(" Enter the name of candidate: ")
candidate(index)=Convert.toInt32(Console.Readline())
candidate(index) -=1
Loop
End Sub
End Module
謝謝,這是有道理的,我已經習慣了把我的思緒一起在開始,所以移動數組從未出現在我身上。謝謝你的幫助。 – DumbQuesionGuy314