Sign in to follow this  
Followers 0
SpookMeister

Multi-Dimentional Array Question

6 posts in this topic

Is there a way to compare multi-dimentional arrays as a whole, without itterating through the array?

Something like this: (which doesnt work BTW)

HotKeySet("{ESC}", "Terminate")
HotKeySet("{F5}", "compare")
HotKeySet("{F6}", "changeA")
HotKeySet("{F7}", "changeB")

Global $testA[3][3]
Global $testB[3][3]

For $x = 0 to 2
    for $y = 0 to 2
        $testA[$x][$y]=111
        $testB[$x][$y]=111
    Next
Next

while 1
    Sleep(1000)
WEnd

Func compare()
    If $testA = $testB Then
        MsgBox(0,"Compare","They are the same")
    Else
        MsgBox(0,"Compare","They do not match")
    EndIf
EndFunc

Func changeA()
    $testA[1][1]=121
EndFunc

Func changeB()
    $testA[1][1]=111
EndFunc

Func Terminate()
    Exit
EndFunc

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites



Is there a way to compare multi-dimentional arrays as a whole, without itterating through the array?

Sorry, no way, other than to loop through the array and compare values.

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

Currently, there is no built-in feature for comparing arrays, other than looping through and comparing element by element.

What would the requirements for equality be?

  • Same number of dimensions
  • Each dimension is the same size
  • Same contents for corresponding elements
At different times, it is important to know which of these conditions failed. Just asking $a = $b doesn't let you know why it failed. You can check that when you are doing the looping to compare.

Well, I guess I could write something like, but it is not my highest priority right now. Work, bug fixes, Work AutoIt debugger, etc. Hmm I do have Variant rewrite on my to-do list. Maybe I can sneak it in there. ;) This may show up in the beta, but do not expect it for a while.


David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Share this post


Link to post
Share on other sites

Is there a way to compare multi-dimentional arrays as a whole, without itterating through the array?

Something like this: (which doesnt work BTW)

HotKeySet("{ESC}", "Terminate")
HotKeySet("{F5}", "compare")
HotKeySet("{F6}", "changeA")
HotKeySet("{F7}", "changeB")

Global $testA[3][3]
Global $testB[3][3]

For $x = 0 to 2
    for $y = 0 to 2
        $testA[$x][$y]=111
        $testB[$x][$y]=111
    Next
Next

while 1
    Sleep(1000)
WEnd

Func compare()
    If $testA = $testB Then
        MsgBox(0,"Compare","They are the same")
    Else
        MsgBox(0,"Compare","They do not match")
    EndIf
EndFunc

Func changeA()
    $testA[1][1]=121
EndFunc

Func changeB()
    $testA[1][1]=111
EndFunc

Func Terminate()
    Exit
EndFunc

<{POST_SNAPBACK}>

if you're comparing to see if the arrays are exactly the same, i remember a while back someone made a UDF that works like _ArrayToString() to convert a multidimensional array to a string... you could find that UDF (i know i saw it in this forum, but they may have posted a finished product in scripts and scraps also) and convert both arrays to strings then compare the strings.

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

if you're comparing to see if the arrays are exactly the same, i remember a while back someone made a UDF that works like _ArrayToString() to convert a multidimensional array to a string... you could find that UDF (i know i saw it in this forum, but they may have posted a finished product in scripts and scraps also) and convert both arrays to strings then compare the strings.

<{POST_SNAPBACK}>

Thanks!! that comment gave me the idea I needed. ;) Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites

Thanks!! that comment gave me the idea I needed.  ;)

<{POST_SNAPBACK}>

cool, glad i could help.

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
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
Sign in to follow this  
Followers 0