Public Function weishu(sz() As String) As Integer
Dim i As Integer
Dim count As Integer
On Error GoTo BoundError
For i = 1 To 61 '不会有这么多维数的数组,vb最多支持60维
count = LBound(sz(), i)
Next
BoundError:
weishu = i - 1
End Function
然后再用函数判断数组长度就可以了.
Public Function changdu(shuzu() As String) As Integer
Dim count As Integer
Dim i As Integer
If IsArray(shuzu) And weishu(shuzu) Then
count = 1
For i = 1 To weishu(shuzu)
count = count * (UBound(shuzu, i) - LBound(shuzu) + 1)
Next i
End If
changdu = count
End Function
其实方法很多的,因为我是初学,所以只好用这些最笨的方法了.
其实判断数组维数的方法以前有朋友介绍过用 copymemory方法解决的,可是我不是十分熟练,所以就没有贴出来!!
用ubound()[取数组的上限]和lbound()[取数组的下限]内部函数取
如:
ubound(tmp,2)表示取第2维的上限。
ubound(tmp,1) or ubound(tmp)表示取第1维的上限。
lbound(tmp,2)表示取第2维的下限。
lbound(tmp,1) or lbound(tmp)表示取第1维的下限。