Jump to content

Array compare?


Recommended Posts

Anyone any idea on how to compare if 2 sets of arrays are equivalent, if there's such a UDF that can do that?

The speed of sound is defined by the distance from door to computer divided by the time interval needed to close the media player and pull up your pants when your mom shouts "OH MY GOD WHAT ARE YOU DOING!!!"

Link to comment
Share on other sites

  • Moderators

Anyone any idea on how to compare if 2 sets of arrays are equivalent, if there's such a UDF that can do that?

The array elements or the values of the elements, 1 dimensional or more? An example of what you want would be great :lmao:

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

2-dimension arrays

initially i tried something like:

Dim $TestArray1[2][2]
Dim $TestArray2[2][2]

$TestArray1[0][0] = 1
$TestArray1[0][1] = 1
$TestArray2[1][0] = 1
$TestArray2[1][1] = 1

If $TestArray1 = $TestArray2 Then ;I know...that was pretty dumb...
MsgBox(0, "", "Equal")

Exit

EndIf

MsgBox(0, "", "Not equal")

which i later realised that I can't compare arrays this way

:lmao:

The speed of sound is defined by the distance from door to computer divided by the time interval needed to close the media player and pull up your pants when your mom shouts "OH MY GOD WHAT ARE YOU DOING!!!"

Link to comment
Share on other sites

  • Moderators

Do they have to be in the same exact order? Like $1[0][1] has to equal $2[0][1]?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Do they have to be in the same exact order? Like $1[0][1] has to equal $2[0][1]?

yea, comparing order by order

so long as i'm comparing if both the arrays are equivalent

:">

The speed of sound is defined by the distance from door to computer divided by the time interval needed to close the media player and pull up your pants when your mom shouts "OH MY GOD WHAT ARE YOU DOING!!!"

Link to comment
Share on other sites

  • Moderators

yea, comparing order by order

so long as i'm comparing if both the arrays are equivalent

:">

Sorry, I was watching a movie... Is this what you're after?
Dim $Test1[3][2]
$Test1[1][0] = 'A'
$Test1[1][1] = 'B'
$Test1[2][0] = 'C'
$Test1[2][1] = 'D'
Dim $Test2[3][2]
$Test2[1][0] = 'A'
$Test2[1][1] = 'B'
$Test2[2][0] = 'C'
$Test2[2][1] = 'D'
If _Array2DimCompare($Test1, $Test2) Then
    MsgBox(64, 'Info1', 'Arrays are identical')
Else
    MsgBox(16, 'Error1', 'Arrays are not identical')
EndIf

Dim $Test3[3][2]
$Test3[1][0] = 'A'
$Test3[1][1] = 'B'
$Test3[2][0] = 'C'
$Test3[2][1] = 'D'
Dim $Test4[3][2]
$Test4[1][0] = 'A'
$Test4[1][1] = 'B'
$Test4[2][0] = 'C'
$Test4[2][1] = 'd'
If _Array2DimCompare($Test3, $Test4) Then
    MsgBox(64, 'Info2', 'Arrays are identical')
Else
    MsgBox(16, 'Error2', 'Arrays are not identical')
EndIf

Func _Array2DimCompare($Array1, $Array2, $iBase1 = 1, $iBase2 = 0, $iCase = 1)
    If UBound($Array1, 1) <> UBound($Array2, 1) Then Return SetError(1, 0, 0)
    If UBound($Array1, 2) <> UBound($Array2, 2) Then Return SetError(2, 0, 0)
    For $iCC = $iBase1 To UBound($Array1, 1) - 1
        For $xCC = $iBase2 To UBound($Array1, 2) - 1
            If $iCase Then
                If Not ($Array1[$iCC][$xCC] == $Array2[$iCC][$xCC]) Then _
                    Return SetError(3, 0, 0)
            Else
                If Not ($Array1[$iCC][$xCC] = $Array2[$iCC][$xCC]) Then _
                    Return SetError(3, 0, 0)
            EndIf
        Next
    Next
    Return 1
EndFunc
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

:ph34r: Good to know this worked for you :lmao:

Hi SmOke_N,

sorry for the late reply.

I've yet to test the script as I was away from office and my scripting machine for the past few days.

But reading from the code itself, it is exactly what I wanted and I believe it should work.

I'll try it out and let you know again when I get back to the office.

Thanks again for your help and attention.

:geek:

The speed of sound is defined by the distance from door to computer divided by the time interval needed to close the media player and pull up your pants when your mom shouts "OH MY GOD WHAT ARE YOU DOING!!!"

Link to comment
Share on other sites

Hi SmOke_N,

I've tried it today and it works perfectly as expected

Thanks for the help :lmao:

The speed of sound is defined by the distance from door to computer divided by the time interval needed to close the media player and pull up your pants when your mom shouts "OH MY GOD WHAT ARE YOU DOING!!!"

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...