PDA

View Full Version : Check if a Dynamic Array has been ReDim'ed...



MattKlein
05-22-2008, 12:05 PM
Is there a method built into VBA to check if a dynamic array has already be dimensioned? (I'm pretty new to VB and VBA) I am currently using


if join(MyArray) = "" then


However, it feels sloppy and causes unneeded overhead on large arrays. True, I could have a boolean value keep track if its been ReDim'ed, but that isn't piratical if I'm passing an array to a function when that array may not have been initialized.

Thoughts?

Bob Phillips
05-22-2008, 01:15 PM
Function IsArrayAllocated(Arr As Variant) As Boolean
On Error Resume Next
IsArrayAllocated = Not (IsError(LBound(Arr))) And _
IsArray(Arr) And _
(LBound(Arr) <= UBound(Arr))
End Function