Consulting

Results 1 to 2 of 2

Thread: Check if a Dynamic Array has been ReDim'ed...

  1. #1

    Check if a Dynamic Array has been ReDim'ed...

    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

    [vba]
    if join(MyArray) = "" then
    [/vba]

    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?
    Vow this day in to the grounds of ergo post proctor hoctor, vis-a-vis telemundo.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]


    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
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •