testing for a null array
Author Message
testing for a null array

Is there some way to test whether an array has any elements in it?

dim aArray() as double
if blah then
redim aArray(0)
aArray(0) = 1
endif

This isn't what my code really is, but just an example of what I'm looking
for.
I can't test to see if aArray() has any elements by using UBound(..) because
I get a subscript out of range error when aArray() is empty.  I can't use
IsNull(..) either, because that
Is there another way to figure out if aArray is null?

thanks,
Tom Warner

Fri, 11 Mar 2005 15:33:44 GMT
testing for a null array
Hi Tom,

Store your array in a variant once filled and then test it with a function:
----------------------------------------------------
Function IsBounded(vArray as Variant) as Boolean
On Error Resume Next
IsBounded = IsNumeric(UBound(vArray))
End Function
----------------------------------------------------

Hope this helps,
regards,
Astrid

So that all can benefit from the discussion, please post all follow-ups to the newsgroup.
Visit the MVP Word FAQ site at http://www.mvps.org/word/

Quote:
> Is there some way to test whether an array has any elements in it?

> dim aArray() as double
> if blah then
>     redim aArray(0)
>     aArray(0) = 1
> endif

> This isn't what my code really is, but just an example of what I'm looking
> for.
> I can't test to see if aArray() has any elements by using UBound(..) because
> I get a subscript out of range error when aArray() is empty.  I can't use
> IsNull(..) either, because that
> Is there another way to figure out if aArray is null?

> thanks,
> Tom Warner

Fri, 11 Mar 2005 15:47:26 GMT
testing for a null array
Ah, you're the man.  Thanks.

Hi Tom,

Store your array in a variant once filled and then test it with a function:
----------------------------------------------------
Function IsBounded(vArray as Variant) as Boolean
On Error Resume Next
IsBounded = IsNumeric(UBound(vArray))
End Function
----------------------------------------------------

Hope this helps,
regards,
Astrid

So that all can benefit from the discussion, please post all follow-ups to
the newsgroup.
Visit the MVP Word FAQ site at http://www.mvps.org/word/

Quote:
> Is there some way to test whether an array has any elements in it?

> dim aArray() as double
> if blah then
>     redim aArray(0)
>     aArray(0) = 1
> endif

> This isn't what my code really is, but just an example of what I'm looking
> for.
> I can't test to see if aArray() has any elements by using UBound(..)
because
> I get a subscript out of range error when aArray() is empty.  I can't use
> IsNull(..) either, because that
> Is there another way to figure out if aArray is null?

> thanks,
> Tom Warner

Fri, 11 Mar 2005 16:26:48 GMT

 Page 1 of 1 [ 3 post ]

Relevant Pages