when does vba ubound function return minus one (-1)

I sometimes define dynamic arrays as follows

dim ary()
redim ary(-1 to -1)  ' useful for "isempty" tests:  if ubound(ary) = -1 then debug.print "it is empty"

But, I seem to remember that there are other conditions in which ubound can return minus one.  

This is a vba questions, not a visual studio question. (visual studio help file describes a minus 1 return, but that is not helpful).

rberke
LVL 5
rberkeConsultantAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
I don't know of any other situation where uBound would give -1. If you just do

Dim ary()
MsgBox uBound(ary)

you'd get an error.
0
Rory ArchibaldCommented:
If you declare an array like:
Dim ary(-2 to -1)

Open in new window

then Ubound would of course return -1.

It will also be the case if say you use a function like Filter (that always returns an array) and nothing in the array matches your criteria - in which case UBound returns -1 and LBound returns 0.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rberkeConsultantAuthor Commented:
Aha !!!

In the distant past I had code that used

x = split(strParameters)
if ubound(x) = -1 then doSomething

But, my memory played a trick on me, and all I could remember was that ubound sometimes returned -1.  It was really bugging me that I could not remember WHY. With Rory's help I now remember that it happened when strParameters contained an empty string.

Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.