Private Sub Command1_Click()
Dim a(),b(),blnFlag As Boolean,F%
Dim i%,j%,k%
ReDim a(1 To 6,1 To 2)
a(1,1) = "2"
a(1,2) = "3a"
a(2,1) = "11"
a(2,2) = "5"
a(3,1) = "34"
a(3,2) = "11t"
a(4,1) = "55"
a(4,2) = "3a"
a(5,1) = "57"
a(5,2) = "11t"
a(6,1) = "72"
a(6,2) = "3a"
ReDim b(1 To 2,1 To 1) ' B(1,1)=3a B(2,1)=3个
b(1,UBound(b,2)) = "" ' a(LBound(a,1),LBound(a,2))
For i = LBound(a,1) To UBound(a,1)
For j = LBound(a,2) To UBound(a,2)
blnFlag = False
For k = LBound(b,2) To UBound(b,2)
If a(i,j) = b(1,k) Then blnFlag = True:Exit For
Next
If blnFlag Then
b(2,k) = b(2,k) + 1
Else
b(1,UBound(b,2)) = a(i,j)
b(2,UBound(b,2)) = 1
ReDim Preserve b(1 To 2,LBound(b,2) To UBound(b,2) + 1) '保留原值重定义数组
b(1,UBound(b,2)) = ""
b(2,UBound(b,2)) = 0
End If
Next
Next
For k = LBound(b,2) To UBound(b,2)
Print b(1,k),b(2,k)
Next
End Sub
'b 数组中二维下标的位置换了一下,以便于 保留原值重定义数组 而不出错!