我怎么能简单地调查给定数组中的项目数。我用了这个代码,但是有点费力
myArr=Array("frog", "cat", "bat", "rat", "horse")
for i=0 to UBound(myArr)
' Msgbox i +1 & ".item: " & myArr(i)
next
Msgbox i & " items in this array:" & vbcrlf & Join(myArr)
Run Code Online (Sandbox Code Playgroud)
谢谢
嗯……你的代码中有它。UBound(Array)返回上限,即最高的现有项目。UBound(myArr) + 1是它的长度,因为索引是从零开始的。
Msgbox (ubound(myArr) + 1) & " items in this array:" & vbcrlf & Join(myArr)
编辑:当您已经使用时ubound,为什么需要循环和变量i来计数。