Results 1 to 4 of 4

Thread: How many dimensions?

  1. #1

    Thread Starter
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228

    How many dimensions?

    Is there a way to find out how many dimensions a given array has? And the total ammount of elements in the array? Please help me.
    Luke

  2. #2
    Lively Member neodatatype's Avatar
    Join Date
    Aug 2002
    Location
    Italy
    Posts
    103

    Lightbulb

    You can do it via API

    This can tell you the number of dimensions:

    Code:
    Declare Function ArrayPtr Lib "msvbvm60" Alias "VarPtr" (ptr() As Any) As Long
    Declare Function CopyMemoryA Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal BytesLen As Long) As Long
    
    'Use like this:  ArrayDimensionCount(ArrayPtr(p()))
    Function admArrayDimensionCount(lpA As Long) As Long
        ' Test: passed
        Dim Dims As Integer
        Dim lpA2 As Long
        
        Call CopyMemoryA(lpA2, ByVal lpA, 4)
        If (lpA2 > 0) Then
            Call CopyMemoryA(Dims, ByVal lpA2, 2)
            admArrayDimensionCount = Dims
        Else
            admArrayDimensionCount = 0
        End If
    
    End Function
    You can get the number of items in this way:

    Code:
    Count = UBound(myArray) - LBound(myArray) + 1
    Cya
    > NeoDataType.net <

    Try my Free .Net Reporting Tool!

  3. #3
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    The easy way...

    Public Function ArrayDimensions(ParamArray Arr() As Variant) As Integer
    Dim K As Integer, DM As Integer

    On Error GoTo Err_Exit
    For K = 1 To 1000
    DM = UBound(Arr(0), K)
    Next K

    ArrayDimensions = -1
    Exit Function
    Err_Exit:
    ArrayDimensions = K - 1
    Err.Clear
    End Function

  4. #4
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    Forgot to put the code tangs

    Code:
    Public Function ArrayDimensions(ParamArray Arr() As Variant) As Integer
        Dim K As Integer, DM As Integer
        
        On Error GoTo Err_Exit
        For K = 1 To 1000
            DM = UBound(Arr(0), K)
        Next K
        
        ArrayDimensions = -1
        Exit Function
    Err_Exit:
        ArrayDimensions = K - 1
        Err.Clear
    End Function

Posting Permissions

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



Click Here to Expand Forum to Full Width