How could I investigate simply the number of items in a given array. I used this code, but it's a bit laborious
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)
Thanks
Umm... you have it in your code. UBound(Array)
returns the upper bound, which is the highest existing item. UBound(myArr) + 1
is its length, because the index is zero based.
Msgbox (ubound(myArr) + 1) & " items in this array:" & vbcrlf & Join(myArr)
EDIT: While you are using ubound
already, why do you need a loop & a variable i
to count.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With