设计思想: 在VB中数姐最大维数是60,所以我们通过错误捕捉来处理这个问题,在这里我们用到UBound函数 Public Function ArrayRange(mArray As Variant) As Integer Dim i As Integer Dim Ret As Integer Dim ErrF As Boolean ErrF = False On Error GoTo ErrHandle '判断代入的参数是否为数组 If Not IsArray(mArray) Then ArrayRange = -1 Exit Function End If 'VB中数组最大为60 For i = 1 To 60 '用UBound函数判断某一维的上界,如果大数组的实际维数时产生超出范围错误, ' 此时我们通过Resume Next 来捕捉错这个错误 Ret = UBound(mArray,i) If ErrF Then Exit For Next i '最后返回 ArrayRange = Ret Exit Function ErrHandle: Ret = i - 1 ErrF = True Resume Next End Function
原文链接:https://www.f2er.com/vb/261319.html