Dou*_*owe 0 vbscript arraylist mscorlib
这是我的代码:
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()
Run Code Online (Sandbox Code Playgroud)
我收到一条错误消息:“ mscorlib:索引超出范围。必须为非负数,并且必须小于集合的大小。参数名称:Index”
我不知道这是什么问题,有人可以帮我解决吗?谢谢。
.NET System.Collections.ArrayList类使用基于0的索引:第一个元素在索引0处,最后一个元素在index处Count - 1。For循环的最后一次迭代会导致错误,因为它尝试访问index处Count不存在的元素。
修改For循环,使其从0计数到myArrayList.Count - 1:
For i = 0 To myArrayList.Count - 1
WScript.StdOut.WriteLine myArrayList(i)
Next
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
791 次 |
| 最近记录: |