谢谢

解决方案 »

  1.   

    给你写了一个例子。Dim a() As Integer
    Dim b() As IntegerPrivate Sub Command1_Click()Dim eq As BooleanFor Each i In b
        eq = False
        For Each j In a
            If i = j Then
                eq = True
                Exit For
            End If
        Next
        If eq = False Then
            ReDim Preserve a(UBound(a) + 1)
            a(UBound(a)) = i
        End If
    NextFor Each i In a
        Print i
    NextEnd SubPrivate Sub Form_Load()ReDim a(5) As Integer
    ReDim b(3) As IntegerFor i = 0 To 5
        a(i) = i
    Next i
    For i = 0 To 3
        b(i) = i + 4
    Next iEnd Sub
      

  2.   

    除了循环,没有更好的办法。但是,最好不要做嵌套循环,太慢了。
    下面是一个利用list控件的例子:在窗体通用段声明:
    Private Declare Function SendMessagebyString Lib _
    "user32" Alias "SendMessageA" (ByVal hWND As Long, _
    ByVal wMsg As Long, ByVal wParam As Long, _
    ByVal lParam As String) As LongPrivate Const LB_FINDSTRINGEXACT = &H1A2运行代码:
    list1.clear
    list1.sorted = true '支持排序,如果不需要可以去掉for i=0 to ubound(arr1)
    list1.additem cstr(arr1(i))
    next ifor i=0 to ubound(arr2)
    if SendMessagebyString(list1.hWnd, LB_FINDSTRINGEXACT, -1, cstr(arr2(i))< 0 then
    list1.additem arr2(i)
    endif
    next i redim arr1(list1.listcount - 1)
    for i = 1 to list1.listcount -1
    arr1(i) = val(list1.list(i))
    next i