|
-
Aug 22nd, 2002, 11:28 AM
#1
Thread Starter
Frenzied Member
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.
-
Aug 22nd, 2002, 12:00 PM
#2
Lively Member
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
-
Aug 22nd, 2002, 12:33 PM
#3
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
-
Aug 22nd, 2002, 12:34 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|