Public Function IsReDimmed(ByRef varArrayToCheck) As Boolean
' Checks a dynamic array to see if it has been ReDim'med.
' This is to prevent errors before applying LBound() or UBound().
' Returns False if varArrayToCheck is dynamic and
' never has been ReDim'med or just has been erased.
' 2001-08-11. Cactus Data ApS, CPH. Gustav Brock.
Dim booIsReDimmed As Boolean
On Error GoTo Err_IsReDimmed
If IsArray(varArrayToCheck) = True Then
' Check if varArrayToCheck is ReDim'med.
' LBound() will fail if varArrayToCheck not has been ReDim'med.
booIsReDimmed = LBound(varArrayToCheck) Imp True
' No error raised; varArrayToCheck is ReDim'med.
' varArrayToCheck is not an array.
IsReDimmed = booIsReDimmed
Select Case Err
' Subscript (array index) out of range.
' varArrayToCheck is dynamic and not ReDim'med.
' Other error.
' Exit function returning False.
Open in new window
Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.
Public Function Fn_IsArrayInitialized(ByVal varArray As Variant) As Boolean
On Error Resume Next
Fn_IsArrayInitialized = Not IsError(UBound(varArray) >= 0)
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.
One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.