これは私のコードの一部にすぎませんが、問題が発生しています。コードの意図された目的は、ユーザーの入力を受け取り、それを配列のサイズにすることです。ただし、入力した値に関係なく、「インデックスは配列の範囲外でした」というエラーが発生します。
コードは次のとおりです。
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