Tell me I'm not crazy

Bob Sneidar bobs at twft.com
Mon Sep 19 16:42:27 EDT 2011


I also ran into comparing arrays in this fashion. First of all, comparing arrays is cASE sENSITIVE (if I remember correctly). Secondly some normal operators like empty do not work on arrays. Arrays ALWAYS report empty! (At least the do for me). 

If the arrays are not terribly large, try using the printKeys() function to convert the arrays to text, and compare them that way. I think sqlYoga has an array comparison function as well, giving you a clue that a simple comparison may not be enough. 

Disclaimer: I may be wrong about any or all of the things I post on this list! 

Bob


On Sep 19, 2011, at 1:30 PM, Tereza Snyder wrote:

> I recently encountered a problem implementing an undo function in a script. I needed to compare two arrays to see if any values had changed, like this:
> 
> put (tArray1 <> tArray2) into sDirtyFlag
> 
> so that sDirtyFlag would be true when the arrays failed to match. However, sDirtyFlag was always false! No matter what! 
> 
> I put the two arrays into globals and compared them in the message box, like this:
> 
> put (gArray1 = gArray2), and the result was always correct. I thought there was some hidden horrible error in my script that dementia prevented me from seeing, until I realized that in my script I was using "<>" not "=" to compare. 
> 
> See if the following script, pasted into a button, mystifies you the way it did me. If you comment out the line:
> 
> put "xx" into  tTestA2["low2"]
> 
> so that the arrays ARE equal you might see, as I did, that the comparison is correct.
> 
> Evidently in LiveCode 4.5.3, buildnumber 1444, on MacOS 10.6.8, 
> 
> "(tTestA1 <> tTestA2)" is not the same as "not(tTestA1 = tTestA2)" when the arrays are unequal.
> 
> (I apologize that the example is so elaborate, I was attempting to reproduce the error environment.)
> 
> 
> tereza
> 
> -- mind the linewraps
> ------------------------------
> 
> on mouseUp
>    DoArrayComparison
> end mouseUp
> 
> on DoArrayComparison
>    -- create 1 array
>    repeat for each item iii in "low1,low2,low3"
>        repeat for each item ii in "lower1,lower2,lower3"
>            repeat for each item i in "lowest1,lowest2,lowest3"
>                put "data" && iii && ii && i into tA1[iii][ii][i]
>            end repeat
>        end repeat
>    end repeat
>    -- create 2 arrays from it
>    put tA1 into tTestA1
>    put tTestA1 into tTestA2
>    -- make them unequal
>    put "xx" into  tTestA2["low2"]
>    -- do three comparisons
>    put "(tTestA1 = tTestA2)="& (tTestA1 = tTestA2) &cr& \
>            "(tTestA1 <> tTestA2)="& (tTestA1 <> tTestA2)  &cr& \
>            "not(tTestA1 = tTestA2)="& not(tTestA1 = tTestA2) 
> end DoArrayComparison
> 
> -------------------------------
> 
> -- 
> Tereza Snyder
> Califex Software, Inc.
> <www.califexsoftware.com>
> 
> 
> 
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list