如果我有以下数组: Dim Array(4, 10) As String Array(0, 0) = "100" Array(0, 1) = "200" Array(1, 0) = "300" Array(1, 1) = "400" Array(1, 2) = "500" Array(1, 3) = "600" 我如何获得以下计数: 0 = 21 = 4 听起来你正试图计算
Dim Array(4, 10) As String Array(0, 0) = "100" Array(0, 1) = "200" Array(1, 0) = "300" Array(1, 1) = "400" Array(1, 2) = "500" Array(1, 3) = "600"
我如何获得以下计数:
0 = 2 1 = 4听起来你正试图计算数组每个维度中非Nothing值的数量.以下功能将允许您这样做
Public Function CountNonNothing(ByVal data As String(,), ByVal index As Integer) As Integer Dim count = 0 For j = 0 To data.GetLength(1) - 1 If data(index, j) IsNot Nothing Then count += 1 End If Next Return count End Function
它可以像这样调用
Dim count1 = CountNonNothing(Array, 0) Dim count2 = CountNonNothing(Array, 1)