TA的每日心情 | 开心 2015-10-19 13:26 |
---|
签到天数: 2 天 连续签到: 2 天 [LV.1]测试小兵
|
本帖最后由 kavensyw 于 2010-10-29 19:13 编辑
用Dicitionary Object返回值
简单示意如下
Dim oDic1,odic2
Set oDic1 = CreateObject("Scripting.Dictionary")
Set oDic2 = CreateObject("Scripting.Dictionary")
Call GetData1(oDic1)
Call GetData2(oDic2)
oItems1 = oDic1.Items
oItems2 = oDic2.Items
'假定两边数量一致
'循环比较,去掉了左右空格
For i=0 To oDic1.Count-1
If Trim(oItems1(i))<>Trim(oItems2(i)) Then
MsgBox "两边值不等:位置"&(i+1)&vbCrLf _
&"左边-"&oItems1(i)&vbCrLf _
&"右边-"&oItems2(i)
End If
Next
oDic1.RemoveAll
oDic2.RemoveAll
Set oDic1 =Nothing
Set oDic2 =Nothing
'Key存放a,b,c
'value存放e,f,g
Function GetData1(oDic)
Dim a,b,c
'Example
a=1:b=2:c=3
oDic.Add 1,a
oDic.Add 2,b
oDic.Add 3,c
End Function
Function GetData2(oDic)
Dim e,f,g
'Example
e=1:f=555:g=3
oDic.Add 1,e
oDic.Add 2,f
oDic.Add 3,g
End Function |
|