Public Function IsArrayDimensioned(varArray As Variant) As Boolean
'*Purpose: Checks if an array has been properly dimensioned
'*Accepts: -varArray: an array which existence is to be verified
'*Returns: a Boolean variable: TRUE if the array has been properly
'* dimensioned, FALSE otherwise
'*Uses: uses the rtlMoveMemory API - to be declared in the
'* general section
'*Remarks: A FIXED array e.g. Dim A(2) is ALWAYS dimensioned
'* even if it has been ERASED!
Dim lngPointerToVariantArray As Long
CopyMemory lngPointerToVariantArray, ByVal VarPtr(varArray) + 8, ByVal 4&
Dim lngPointerToArrayStructure As Long
CopyMemory lngPointerToArrayStructure, ByVal lngPointerToVariantArray, ByVal 4&
Select Case lngPointerToArrayStructure <> 0
Case True
IsArrayDimensioned = True
Case False
IsArrayDimensioned = False
End Select
End Function
Following excerpt prints TRUE in response to the above routine. In the General Section:
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(lngTarget As Any, lngSource As Any, ByVal lngLengthInBytes As Long)
Somewhere in the mainline code:
Dim a_intA() As String
Dim i As Integer
ReDim a_intA(9)
Debug.Print IsArrayDimensioned(a_intA)
_________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]