这么一比划就明白了,很容易的。
图片附件: 游客没有浏览图片的权限,请
登录 或
注册
代码如下:
Private Sub Command1_Click()
Dim a(9) As String, b(9) As String, c() As String, d() As String
Dim i As Integer, j As Integer, k As Integer
Randomize
Me.Cls
Print "数组A", "数组B"
For i = 0 To 9
a(i) = Chr(65 + 5 * Rnd)
'随机产生10个字母到数组a中
b(i) = Int(100 * Rnd)
'随机产生10个数到数组b中
Print a(i), b(i)
'显示数组内容
Next
k = 0
ReDim c(k): ReDim d(k)
For i = 0 To 8
If a(i) <> "-1" Then
ReDim Preserve c(k): ReDim Preserve d(k)
'不改变数组CD前面值,增加数组下标
c(k) = a(i): d(k) = b(i)
For j = i + 1 To 9
If a(j) = a(i) Then
d(k) = d(k) & "," & b(j)
'合并数组B
a(j) = "-1"
'修改数组A中相同内容为不存在的元素,防止重复判断
End If
Next
k = k + 1
End If
Next
Print "数组C", "数组D"
For i = 0 To UBound(c)
Print c(i), d(i)
'显示合并后数组内容
Next
End Sub