帮我修改这段vb代码

先看一下这段代码:Private Sub Command1_Click()a1 = Split(Text1.Text)a2 = Split(Text2.Text)For i = 0 To UBound(a1) If a1(i) = a2(i) Then Text3.Text = Text3.Text & "相同" & " " Else Text3.Text = Text3.Text & "不相同" & " " End IfNext iEnd Sub1.这段代码只能对上下两组相同数组的数字进行处理,否则会提示下标越界.如:text1:74 85 96 36 25 14text2:74 85 69 37 45怎样修改让它显示"不相同"2.这段代码只能对上下对比,要修改如下: 让text1里面的第一个数组数与text2的第二个数组数对比,第二个数组数与第三个数组数对比,(就是说text2里面的第一个数组不用对比,其它正常)text1比到最后一个时结果就显示"相同/不相同"如下:text1:74 85 96 36 25 14text2:36 74 85 45 65 72text3:相同 相同 不相同 不相同 不相同 相同/不相同 (因为36不用比较)谢谢各位了!
2026-12-05 02:54:29
推荐回答(2个)
回答1:

1、首先比较UBound(a1)和UBound(a2)是否相同,如果相同,再比较其它就不会出错了,否则直接就是不相同。
2、For i = 0 To UBound(a1)
If a1(i) = a2(i) Then 改为

For i = 0 To UBound(a1)-1
If a1(i) = a2(i+1) Then
即可错位比较!

回答2:

if UBound(a1)<>UBound(a2) then '如果这两个数组元素个数不相同
***
if UBound(a1)>UBound(a2) then ***
if UBound(a1)