三維數組求元素個數公式?
三個方向上元素數目相乘。 這個答案明顯是被強制聲明數組下標從1開始了。 計算元素個數可以采用下面的方式。
Option Base 1 Private Sub Form_Click() Dim i As Integer, j As Integer, k As Integer Dim count As Long Dim a(3, -2 To 2, 5) As Integer For i = LBound(a, 1) To UBound(a, 1) For j = LBound(a, 2) To UBound(a, 2) For k = LBound(a, 3) To UBound(a, 3) count = count + 1 Next k Next j Next i MsgBox count End Sub