rudi Posted December 30, 2009 Share Posted December 30, 2009 Hi.I tried to directly compare two arrays, holding identical data. This fails. Why?expandcollapse popup$ini="C:\my-test.ini" $section="Global" Dim $ReferenceArr[8][2] = [[7], _ ["PortNumber", "12345"], _ ["ConnectionType", "HTTP"], _ ["AutoDial", "0"], _ ["UseVendor", "0"], _ ["UserPassword", "somethingcryptic"], _ ["UserName", "someusername"], _ ["ConnectionAddress", "http://update.customer.de:12345/path/path/"]] for $i=1 to $ReferenceArr[0][0] IniWrite($ini,$section,$ReferenceArr[$i][0],$ReferenceArr[$i][1]) Next ; Reading the INI content to a 2nd Array: $INIArr=IniReadSection($ini,$section) ; compare it to the Reference Array fails: if $INIArr=$ReferenceArr Then MsgBox(0,"Match","Arrays match") Else MsgBox(48,"Mismatch","Arrays do *NOT* match") EndIf ; Comparing Arrays cell by cell *DOES* match: if $INIArr[0][0]=$ReferenceArr[0][0] Then for $i = 0 to $INIArr[0][0] ConsoleWrite($i & "-----------------" & @CRLF) ConsoleWrite( $INIArr[$i][0] & ", " & ($INIArr[$i][0]=$ReferenceArr[$i][0]) & @CRLF) ConsoleWrite( $INIArr[$i][1] & ", " & ($INIArr[$i][1]=$ReferenceArr[$i][1]) & @CRLF) Next Else ConsoleWrite("Arrays don't match for [0][0]" & @CRLF) EndIfConfused, I honestly can't see what's my mistake.Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
somdcomputerguy Posted December 30, 2009 Share Posted December 30, 2009 IniReadSection returns an array, which I guess can only be compared to another array. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
Developers Jos Posted December 30, 2009 Developers Share Posted December 30, 2009 Confused, I honestly can't see what's my mistake.You cannot compare arrays by comparing the Array variablenames. You will have to compare each entry of the 2 arrays and possible first need to sort them both to ensure they are in the correct sequence.Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Der_Andi Posted January 3, 2010 Share Posted January 3, 2010 If the content of both of your array's are in the same sequence, you could compare them like this: #include <Array.au3> If _ArrayToString($array1) = _ArrayToString($array2) Then ;code EndIf Link to comment Share on other sites More sharing options...
James Posted January 3, 2010 Share Posted January 3, 2010 Try this. It was a quick script, and not tested so be careful expandcollapse popup;; Setup the arrays Dim $arrayOne[4] = ["James", "AutoIt", "Script", "FIRe!"] Dim $arrayTwo[3] = ["JaMES", "Autoit", "script"] Dim $arrayThree[4] = ["James", "AutoIt", "Script", "FIRe!"] ;; Compare array one and two ConsoleWrite("-> Test one" & @CRLF) If _ArrayCompare($arrayOne, $arrayTwo) Then MsgBox(0, "", "$arrayOne and $arrayTwo match!") Else MsgBox(0, "", "$arrayOne and $arrayTwo don't match!") EndIf ;; Compare array one and three ConsoleWrite("-> Test two" & @CRLF) If _ArrayCompare($arrayOne, $arrayThree) Then MsgBox(0, "", "$arrayOne and $arrayThree match!") Else MsgBox(0, "", "$arrayOne and $arrayThree don't match!") EndIf Func _ArrayCompare($arrOne, $arrTwo) If UBound($arrOne) = UBound($arrTwo) Then ; Continue because the sizes match For $i = 1 to UBound($arrOne) - 1 If $arrOne[$i] = $arrTwo[$i] Then ContinueLoop Else SetError(0) Return 0 ; Error - the array isn't the same EndIf Next Else SetError(1) Return 0 ; Error - the array isn't the same size EndIf Return 1; Loops matched EndFunc Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now