VB将两个数组进行对比并输出其中相同的数据

两个数组储存的是都是文件名文件大小每个大概7000个数据无序对比2维数组... 两个数组储存的是都是 文件名文件大小 每个大概7000个数据
无序对比 2维数组
展开
 我来答
mzlyh163com
2014-03-09 · 超过11用户采纳过TA的回答
知道答主
回答量:20
采纳率:0%
帮助的人:23.7万
展开全部
专门帮你做了如下 程序,并经调试通过。加分啊!

在程序中增加命令按钮一个,MSHFlexGrid四个,程序如下,
Option Explicit
Dim a(1 To 2000) As Single
Dim b(1 To 2000) As Single

Private Sub Command1_Click()
Dim i, j As Integer
With MSHFlexGrid1
.Rows = 1 + UBound(a)
.Cols = 2
For i = 1 To UBound(a)
.TextMatrix(i, 1) = a(i)
Next
.Col = 1
.Sort = 1 '排序
End With
Call RemoveduplicateRows(MSHFlexGrid1) '删除重复的行

With MSHFlexGrid2
.Rows = 1 + UBound(b)
.Cols = 2
For i = 1 To UBound(b)
.TextMatrix(i, 1) = b(i)
Next
.Col = 1
.Sort = 1 '排序
End With
Call RemoveduplicateRows(MSHFlexGrid2) '删除重复的行

With MSHFlexGrid3
.Rows = MSHFlexGrid2.Rows + MSHFlexGrid1.Rows - 1
.Cols = 2
For i = 1 To MSHFlexGrid1.Rows - 1 ''将前两表的数据合并到第三表
.TextMatrix(i, 1) = MSHFlexGrid1.TextMatrix(i, 1)
Next
For i = 1 To MSHFlexGrid2.Rows - 1
.TextMatrix(MSHFlexGrid1.Rows - 1 + i, 1) = MSHFlexGrid2.TextMatrix(i, 1)
Next
.Col = 1
.Sort = 1 '排序
j = 1
MSHFlexGrid4.Rows = 2
MSHFlexGrid4.Cols = 2
For i = 2 To .Rows - 1
If .TextMatrix(i, 1) = .TextMatrix(i - 1, 1) Then
MSHFlexGrid4.TextMatrix(MSHFlexGrid4.Rows - 1, 1) = .TextMatrix(i, 1) '前第三表中重复的数据列在第四表,此第四表中第1列的数据就是你要的答案
MSHFlexGrid4.Rows = MSHFlexGrid4.Rows + 1
End If
Next
MSHFlexGrid4.Rows = MSHFlexGrid4.Rows - 1
End With
End Sub
Private Sub RemoveduplicateRows(MSH As MSHFlexGrid) '删除重复的行
Dim i, j As Integer
With MSH
i = 1
Do
j = i
If .Rows > 2 Then
Do While j < .Rows - 1
If (.TextMatrix(i, 1) = .TextMatrix(j + 1, 1)) Or VBA.Len(.TextMatrix(j + 1, 1)) = 0 Then '删除重复的行
.RemoveItem (j + 1)
.Refresh
j = j - 1
End If
j = j + 1
Loop
End If
i = i + 1
Loop Until i >= .Rows
End With
End Sub
Private Sub Form_Load()
Dim i As Integer
Randomize
For i = 1 To 2000
a(i) = Val(VBA.Format((Rnd(i) * 100), "#.##")) 'a(1 To 2000), b(1 To 2000)是你已经有的数据,这里由随机数代替
b(i) = Val(VBA.Format((Rnd(i) * 100), "#.##"))
Next
End Sub
匿名用户
2014-03-09
展开全部
是无序对比还是有序对比??
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式