GetArrayDim

The following example function demonstrates how to determine the number of dimensions to an array.

Example

'------------------------------------------------------------------------------

' Function:  GetArrayDim

' Purpose:   Returns the number of dimensions to an array.

' Argument:  An array to evaluate

' Returns:   The number of dimensions if successful

'            Null on error

'------------------------------------------------------------------------------

Public Function GetArrayDim(ByRef arrValue)

If IsArray(arrValue) Then

For i = 1 To 60

On Error Resume Next

UBound arrValue, i

If Err.Number <> 0 Then

GetArrayDim = i-1

Exit Function

End If

Next

GetArrayDim = i

Else

GetArrayDim = Null

End If

End Function

 

'------------------------------------------------------------------------------

' Function:  IsUpperBound

' Purpose:   Returns a Boolean value indicating whether an

'            array has been dimensioned.

' Argument:  An array to evaluate

' Returns:   TRUE or FALSE

'------------------------------------------------------------------------------

Function IsUpperBound(ByRef arr)

  IsUpperBound = False

  If IsArray(arr) Then

    On Error Resume Next

    UBound arr

    If Err.Number = 0 Then IsUpperBound = True

  End If

End Function