如何用vb比较两组数字并找出他们互没有的数字?

来源:百度知道 编辑:UC知道 时间:2024/05/30 11:49:32
比如有两组数字a组和b组,要求他们进行对比,从a组中找出b组没有的数字,从b组中找出a组没有的数字,他这些挑出的数字放在list控件里,假设a组数字是2,3,4,6 b组数字是2,6,7,8,最后结果应该是3,4,7,8,请写出具体代码,谢谢!

我来试试

a()
b()

dim i as integer ,j as integer
dim x as boolean
for i = 0 to ubound(a)
x=true
for j = 0 to ubound(b)
if a(i) = b (j) then
x=false
exit for

endif
next
if x then list1.additem a(i)
next

for i = 0 to ubound(b)
x=true
for j = 0 to ubound(a)
if b(i) = a (j) then
x=false
exit for

endif
next
if x then list1.additem b(i)
next

'楼上的无法解决2,与22判断出错的问题。
'在窗体上加入控件list1,command1,复制下面代码,运行即可。

Option Explicit

Private Sub Command1_Click()
Dim S1 As String, S2 As String, i As Integer, a() As String
S1 = "2,3,4,6" '根据实际情况按此格式修改
S2 = "2,6,7,8" '根据实际情况按此格式修改
S1 = "," & S1 & ",": S2 = "," & S2 & ","
With List1
.Clear
a = Split(S1, ",")
For i = 1 To UBound(a) - 1
If InStr(S2, &qu