Code: Select all
redim items() as integer
print ubound( items ) '- shows -1
redim preserve items( 0 )
print ubound( items ) '- shows 0
'- move array back to zero elements?
redim items() '- compile error
redim items( -1 ) '- runtime error
Instead of adding an additional variable to keep track of the number of items in the array ( e.g. "itemCount += 1: redim preserve items( itemCount-1 )" ), I was experimenting with keeping track of the item count by using only ubound() instead ( e.g. grab the item count when needed with "ubound( items )+1" ). But, if I need to remove items from the array, I like to resize it back down, ideally back to zero elements if needed, so that ubound() reports -1 again.