...keeping track of the item count...
Note that having ubound() as -1 does not always mean there is zero item in an array...
lbound may be negative or above zero
redim items(-5 to -1)
redim items(5 to 9)
ubound may be negative or equal zero
redim items(-5 to -1)
redim items(-4 to 0)
In those cases, to get item count, you may use
itemCount = ubound(items) - lbound(items) + 1
Code: Select all
redim items(-5 to -1) : print lbound(items), ubound(items), ubound(items) - lbound(items) + 1; " element in array" '-5 -1 5
redim items(5 to 9) : print lbound(items), ubound(items), ubound(items) - lbound(items) + 1; " element in array" ' 5 9 5
redim items(-4 to 0) : print lbound(items), ubound(items), ubound(items) - lbound(items) + 1; " element in array" '-4 0 5