有谁知道 "mscorlib: Index was out of range" 在我的 vbscript 代码中意味着什么?

Does anyone know what "mscorlib: Index was out of range" means in my vbscript code?

这是我的代码:

dim myArrayList

function addName

    Wscript.StdOut.WriteLine "What is your Quarterback's name?"
    n = Wscript.StdIn.ReadLine

    Wscript.StdOut.WriteLine "Attempts: "
    a = Wscript.StdIn.ReadLine

    Wscript.StdOut.WriteLine "Completions: "
    c = Wscript.StdIn.ReadLine

    Wscript.StdOut.WriteLine "Yards: "
    y = Wscript.StdIn.ReadLine

    Wscript.StdOut.WriteLine "Touchdowns: "
    t = Wscript.StdIn.ReadLine

    Wscript.StdOut.WriteLine "Interceptions: "
    i = Wscript.StdIn.ReadLine


Set myArrayList = CreateObject( "System.Collections.ArrayList" )
    myArrayList.Add n
    myArrayList.Add a
    myArrayList.Add c
    myArrayList.Add y 
    myArrayList.Add t
    myArrayList.Add i

end function 

addname()

function show
    for i = 1 to myArrayList.count
        Wscript.StdOut.WriteLine myArrayList(i)
    next
end function

show()

我收到一条错误消息, "mscorlib: Index was out of range. Must be non-negative and must be less of the size of the collection. Parameter name: Index"

不知道是什么问题 谁能帮我解决这个问题?谢谢

.NET System.Collections.ArrayList class 使用基于 0 的索引:第一个元素位于索引 0,最后一个元素位于索引 Count - 1For 循环的最后一次迭代导致错误,因为它试图访问索引 Count 处的元素,该元素不存在。

修改您的 For 循环,使其从 0 计数到 myArrayList.Count - 1

For i = 0 To myArrayList.Count - 1
    WScript.StdOut.WriteLine myArrayList(i)
Next