我现在有 A(),B(),C()三个动态数组
我现在想把他们按照上面顺序合并并存入 D() (要注意数组为空的情况)
请给出算法?谢谢!

解决方案 »

  1.   

    '合并A
    if ubound(A) > 0 then
        redim preserve D(ubound(D)+ubound(A)+1)
        for i = 0 to ubound(A)
            D(ubound(D)+i+1) = A(i)
        next
    end if
    '合并B
    if ubound(B) > 0 then
        redim preserve D(ubound(D)+ubound(B)+1)
        for i = 0 to ubound(B)
            D(ubound(D)+i+1) = B(i)
        next
    end if
    '合并C
    if ubound(C) > 0 then
        redim preserve D(ubound(D)+ubound(C)+1)
        for i = 0 to ubound(C)
            D(ubound(D)+i+1) = C(i)
        next
    end if
      

  2.   

    --获取数组的最大下标,如果为空,返回-1
    function MyUBound(byval arr() as string) as long
        on error goto ErrHand
        MyUBound=ubound(arr)
    ErrHand:
        if err.number<>0 then
            MyUbound=-1
        end if
    end function--将一个子数组arrSub合并到arrSum
    sub InputSubToSum(byref arrSum() as string,byval arrSub() as string) 
        dim i as long
        dim iMax as long
        iMax=MyUbound(arrSum)
        for i=0 to MyUbound(arrSub)
           redim preserve arrSum(iMax+1)
           arrSum(iMax+1)=arrSub(i)
           iMax=iMax+1
        next
    end sub InputSubToSum(D,A);
    InputSubToSum(D,B);
    InputSubToSum(D,C);
      

  3.   

    Dim A() As String
        Dim B() As String
        Dim C() As String
        
        For i = 0 To 9
            ReDim Preserve A(i)
            A(i) = i
        Next
        
        For i = 10 To 19
            ReDim Preserve B(i - 10)
            B(i - 10) = i
        Next
        
        For i = 20 To 29
            ReDim Preserve C(i - 20)
            C(i - 20) = i
        Next
        
        Dim D() As String
        ReDim D(0)
        If UBound(A) > 0 Then
            Dim l
            l = UBound(D)
            ReDim Preserve D(l + UBound(A) + 1)
            For i = 0 To UBound(A)
                D(l + i + 1) = A(i)
            Next
        End If
        '合并B
        If UBound(B) > 0 Then
            l = UBound(D)
            ReDim Preserve D(l + UBound(B) + 1)
            For i = 0 To UBound(B)
                D(l + i + 1) = B(i)
            Next
        End If
        '合并C
        If UBound(C) > 0 Then
            l = UBound(D)
            ReDim Preserve D(l + UBound(C) + 1)
            For i = 0 To UBound(C)
                D(l + i + 1) = C(i)
            Next
        End If