在VB中如何获得数组维数,本来是一个简单的问题,但还是有朋友不断问起,为了省事,于是把有关代码片断贴了出来,具体实现过程如下:
Option Explicit Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any,_ Source As Any,ByVal Length As Long) Private Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" (Var() As Any) As Long Public Function GetArrayDims(pvArray() As Variant) As Long '获得数组维数 Dim pArray As Long,ppArray As Long,nDims As Long ppArray = VarPtrArray(pvArray) CopyMemory pArray,ByVal ppArray,4 CopyMemory nDims,ByVal pArray,2 GetArrayDims = nDims End Function