VB 中 2个数组进行对比,如果数组的值全一致,按钮可用,怎么写呢?
自己做了一个循环,但是这样做有问题,不能实现,如果数组的值全一致,按钮可用
For i = 0 To 7
    '转换为大写字母UCase(a)
a(i) = UCase(newsheet.cells(1, i + 1))If (a(i) <> b(i)) Then
MsgBox "列" & i + 1 & "错误:" & newsheet.cells(1, i + 1), "0", "提示"
Command1.Enabled = False
Else
Command1.Enabled = True
End If

解决方案 »

  1.   

    可以分别用jion函数连成一个字符串,然后比较字符串是不是一致
      

  2.   

    For i = 0 To 7
      '转换为大写字母UCase(a)
    a(i) = UCase(newsheet.cells(1, i + 1))If (a(i) <> b(i)) Then
    MsgBox "列" & i + 1 & "错误:" & newsheet.cells(1, i + 1), "0", "提示"
    Command1.Enabled = False
    exit for '这里加个退出代码,继续执行到相同的最后按钮还是会被重新设置为true的
    Else
    Command1.Enabled = True
    End If或者改成这样也行:
    Command1.Enabled = True
    For i = 0 To 7
      '转换为大写字母UCase(a)
    a(i) = UCase(newsheet.cells(1, i + 1))If (a(i) <> b(i)) Then
    MsgBox "列" & i + 1 & "错误:" & newsheet.cells(1, i + 1), "0", "提示"
    Command1.Enabled = False
    exit for '这里加个退出代码,继续执行到相同的最后按钮还是会被重新设置为true的
    End If