Visual Basic Programming Code Examples Visual Basic > Other Code Examples Determine if any two variables are different Determine if any two variables are different The following routines can be used to determine if two variables are identical. 'Purpose : Compares any two variants, including arrays, objects etc. 'Inputs : vItem1 The first item to test. ' vItem2 The second item to test. 'Outputs : Returns True if the variables are identical. 'Notes : 'Assumptions : Function IsSame(vItem1 As Variant, vItem2 As Variant) As Boolean Dim lThisRow As Long, lThisCol As Long, lNumCols As Long On Error GoTo ErrFailed If IsArray(vItem1) Then If Not IsArray(vItem2) Then Exit Function End If If LBound(vItem1) <> LBound(vItem2) Then Exit Function End If If UBound(vItem1) <> UBound(vItem2) Then Exit Function End If If ArrayNumDimensions(vItem1) <> ArrayNumDimensions(vItem2) Then Exit Function End If If ArrayNumDimensions(vItem1) = 1 Then For lThisRow = LBound(vItem1) To UBound(vItem1) If Not IsSame(vItem1(lThisRow), vItem2(lThisRow)) Then Exit Function End If Next Else lNumCols = UBound(vItem1, 2) For lThisRow = LBound(vItem1) To UBound(vItem1) For lThisCol = LBound(vItem1, 2) To lNumCols If Not IsSame(vItem1(lThisRow, lThisCol), vItem2(lThisRow, lThisCol)) Then Exit Function End If Next Next End If 'Items are identical IsSame = True ElseIf IsObject(vItem1) Then IsSame = (vItem1 Is vItem2) Else If Not IsArray(vItem2) Then If IsNull(vItem1) Then IsSame = IsNull(vItem2) Else IsSame = (vItem1 = vItem2) End If End If End If ErrFailed: On Error GoTo 0 End Function 'Purpose : Calculates the number of dimensions in an array 'Inputs : avInArray. The array to evaluate. 'Outputs : The number of dimensions the array has. Function ArrayNumDimensions(avInArray As Variant) As Long Dim lNumDims As Long If IsArray(avInArray) Then On Error GoTo ExitSub Do lNumDims = UBound(avInArray, ArrayNumDimensions + 1) ArrayNumDimensions = ArrayNumDimensions + 1 Loop End If ExitSub: On Error GoTo 0 End Function