且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何找到数组的维数?

更新时间:2023-02-26 18:35:25

是否可以在VBA中找到数组的维数?

这种方法会增加可能的尺寸计数,即60个是内置的最大值(参见注释):

This approach increments the possible dimensions count, 60 being the built in maximum (c.f. comment):

Private Function nDim(ByVal vArray As Variant) As Long
' Purpose: get array dimension (MS)
Dim dimnum     As Long
Dim ErrorCheck As Long    ' OP: As Variant
On Error GoTo FinalDimension

For dimnum = 1 To 60        ' 60 being the absolute dimensions limitation 
    ErrorCheck = LBound(vArray, dimnum)
Next
' It's good use to formally exit a procedure before error handling
' (though theoretically this wouldn't needed in this special case - see comment) 
Exit Function

FinalDimension:
nDim = dimnum - 1

End Function

其他链接(thx @ChrisNeilson)

使用数组的MS

大数组