Compare 2 variants

Posted by:

Function Compare2Variants(C2Var1,C2Var2, C2VarExactMatch As Boolean) As Boolean

Dim C2Var1strList List As String
Dim C2Var2strList List As String
Dim C2VarCount As String
Dim C2Var1intList List As Integer
Dim C2Var2intList List As Integer

Compare2Variants = False
If (UBound(C2Var1)-Lbound(C2Var1)) <> (UBound(C2Var2)-Lbound(C2Var2)) Then
    Compare2Variants = False
    Exit Function               
End If

If C2VarExactMatch Then
    C2VarCount = 0
    ForAll C2Var1Values In C2Var1
        C2Var1strList(C2VarCount) = C2Var1Values    
        C2VarCount = C2VarCount +1 
    End ForAll
    C2VarCount = 0      
    ForAll C2Var2Values In C2Var2
        C2Var2strList(C2VarCount) = C2Var2Values    
        C2VarCount = C2VarCount +1 
    End ForAll
    ForAll x In C2Var1strList
        If Not C2Var1strList(ListTag(x)) = C2Var2strList(ListTag(x)) Then
            Compare2Variants = False
            Exit Function
        End If
    End ForAll
    Erase C2Var1strList 
    Erase C2Var2strList 
Else        
    ForAll C2Var1Values In C2Var1
        If IsElement(C2Var1intList(C2Var1Values)) Then
            C2Var1intList(C2Var1Values) = C2Var1intList(C2Var1Values) + 1                                   
        Else
            C2Var1intList(C2Var1Values) = 1                                 
        End If
    End ForAll
    ForAll C2Var2Values In C2Var2
        If IsElement(C2Var2intList(C2Var2Values)) Then
            C2Var2intList(C2Var2Values) = C2Var2intList(C2Var2Values) + 1                                   
        Else
            C2Var2intList(C2Var2Values) = 1                                 
        End If
    End ForAll
    ForAll y In C2Var1intList
        If IsElement(C2Var2intList(ListTag(y))) = True Then     
            If Not (C2Var1intList(ListTag(y)) = C2Var2intList(ListTag(y))) Then
                Compare2Variants = False
                Exit Function               
            End If              
        Else
            Compare2Variants = False
            Exit Function
        End If
    End ForAll
    Erase C2Var1intList 
    Erase C2Var2intList         
End If

Compare2Variants = True

End Function

1