Option Explicit Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, source As Any, ByVal Length As Long) Declare Function VarPtrArray Lib "msvbvm50.dll" Alias "VarPtr" (Ptr() As Any) As Long Const AppName = "Stanley Pan Hint:"
' ************************************************************************ ' Routine Name : (Public in Standard module) Sub ArrayDimensionTest ' Written By : Stanley ' Programmer : Stanley [ISOLA-J05Q6EYMB] ' Date Writen : 2006-03-30 20:01:07 ' Inputs : N/A ' Outputs : N/A ' Description : ' : ' : ' Called By : ' ************************************************************************ Public Sub ArrayDimensionTest() Dim varArray() As Integer 'dim a variables to contain array ReDim varArray(1) As Integer 'one dimension MsgBox ArrayDims(VarPtrArray(varArray)), vbInformation, AppName ReDim varArray(1, 2) As Integer 'two dimension MsgBox ArrayDims(VarPtrArray(varArray)), vbInformation, AppName ReDim varArray(2, 3, 4) As Integer 'three dimension MsgBox ArrayDims(VarPtrArray(varArray)), vbInformation, AppName ReDim varArray(1, 2, 3, 4) As Integer 'Four dimension MsgBox ArrayDims(VarPtrArray(varArray)), vbInformation, AppName End Sub Public Function ArrayDims(ByVal lpArray As Long) As Integer Dim lAddress As Long CopyMemory lAddress, ByVal lpArray, 4 If lAddress = 0 Then ' The array isn't initilized ArrayDims = -1 Exit Function End If CopyMemory ArrayDims, ByVal lAddress, 2 End Function
|