'********************************************************************

'*

'* Function aryDimensions

'*

'*   Author: NetworkAdminKB.com

'*  Created: 2009-01-17

'* Modified: 2009-01-25

'*

'* Purpose: Return the number of deminsions in the given array.

'*

'*   Input: aryAny = The array to test

'*

'*  Output: Returns 0 if not an array

'*          Returns the number of deminsions in the array.

'*           

'*         

'*   Notes: Arrays are limited to 64 deminsions when all Dimensions are

'*            Zero (0).  The performance of this function will vary by the

'*            the number and size of Dimensions in the array.  Examples,

'*            An Multi-Dimensional array of all ones (1) will show slow

'*            performance around 25 Dimensions,  while all twos (2) will

'*            show slow performance around 15 Dimensions.

'*

'*

'* Changes:

'* 2009-01-18: Rewrite removing hardcoded limit of 10 dimensions.

'* 2009-01-25: Removed call to aryDimensionsErrorCheck

'********************************************************************

Function aryDimensions(ByRef aryAny)

  'Version 2.1 2009-01-25

  Dim x, y, blnFound, strTemp

 

  If Not IsArray(aryAny) Then

    aryDimensions = 0

    Exit Function

  End If 'Not IsArray(aryAny)

 

  x = 0

  blnFound = False

 

  Do Until blnFound

    x = x + 1

    If x = 1 Then

      strTemp = "0"

    Else

      strTemp = strTemp & ",0"

    End If 'x = 1

   

    On Error Resume Next

    'Retrieve the value stored the first element (0), (0,0), (0,0,0), etc.

    Execute("y = aryAny(" & strTemp & ")")

    If Err.Number = 0 Then

      On Error GoTo 0

      'Successfull, correct number dimensions found.

      aryDimensions = x

      blnFound = True

    End If 'Err.Number > 0

  Loop 'Until blnFound

End Function 'aryDimensions

Article ID: 88, Created On: 9/17/2011, Modified: 9/17/2011