LeCarre Posted July 29, 2014 Share Posted July 29, 2014 Whilst hacking out some code my app crashed, gee that never happens... Tracked it down to this odd return value. As written it outputs "Found String at index: 0" The commented out arrays function normally, and return Error 6. Not Found. So it seems odd that Element 0 gets a hit if it is = 0. Autoit v3.3.12.0 #include <Array.au3> Local $Result = -1 Local $A[7] = [0,1,2,3,4,5,6] ; Fail ;Local $A[7] = [1,2,3,4,5,6,7] ; Ok ;Local $A[7] = ["1","2","3","4","5","6","7"] ; Ok ;Local $A[7] = ["0","2","3","4","5","6","7"] ; Ok $Result = _ArraySearch($A,"BigString") if $Result = -1 Then ConsoleWrite("Error: " & @Error & @CRLF) Else ConsoleWrite("FoundString at index: " & $Result & @CRLF) EndIf ConsoleWrite(@AutoItVersion & @CRLF) Link to comment Share on other sites More sharing options...
JohnOne Posted July 29, 2014 Share Posted July 29, 2014 Try this and see if you can figure out why #include <Array.au3> Local $Result = -1 Local $A[7] = ["0","1","2","3","4","5","6"] ; Fail ;Local $A[7] = [1,2,3,4,5,6,7] ; Ok ;Local $A[7] = ["1","2","3","4","5","6","7"] ; Ok ;Local $A[7] = ["0","2","3","4","5","6","7"] ; Ok $Result = _ArraySearch($A,"BigString") if $Result = -1 Then ConsoleWrite("Error: " & @Error & @CRLF) Else ConsoleWrite("FoundString at index: " & $Result & @CRLF) EndIf ConsoleWrite(@AutoItVersion & @CRLF) AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
LeCarre Posted July 29, 2014 Author Share Posted July 29, 2014 Changing it to a string copies the result of the 3rd commented out Array which works fine. I got the strange result when the Zero Element contained a number Zero. I added $A[0] = 0 right after your changes, and got the odd result again. Link to comment Share on other sites More sharing options...
eukalyptus Posted July 29, 2014 Share Posted July 29, 2014 This is because 0 = "String" returns True (line 48 in _Array_Search) $sStr = "BigString" $iNull = 0 If $iNull = $sStr Then ConsoleWrite("! " & $iNull & " = " & $sStr & @CRLF) Else ConsoleWrite("+ " & $iNull & " <> " & $sStr & @CRLF) EndIf If $iNull == $sStr Then ConsoleWrite("! " & $iNull & " == " & $sStr & @CRLF) Else ConsoleWrite("+ " & $iNull & " <> " & $sStr & @CRLF) EndIf jvanegmond 1 DirectSound UDF Direct2D UDF Link to comment Share on other sites More sharing options...
LeCarre Posted July 29, 2014 Author Share Posted July 29, 2014 Thanks for the clear example. Not that I understand why 0 = String, But at least I know it now. i'll have to be using some functions Differently. UBound instead of Counts in Zero Elements. Link to comment Share on other sites More sharing options...
JohnOne Posted July 29, 2014 Share Posted July 29, 2014 When testing a number to a string, AutoIt converts the string to a numerical value. If the string is not a numerical one it is 0. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
LeCarre Posted July 29, 2014 Author Share Posted July 29, 2014 (edited) Ah IC, i'm getting C++ hunger pangs... Changed _Arraysearch($Var,"String") to _Arraysearch($Var,"String",1) to avoid ZeroElement compare. $iCompare Default took me for a joyride Edited July 29, 2014 by LeCarre Link to comment Share on other sites More sharing options...
Richard Robertson Posted July 29, 2014 Share Posted July 29, 2014 (edited) "3278" equals the number 3278. "437f" equals the number 437. "BigString" equals the number 0 because there are no digits to parse. It has to do with the AutoIt variant and implicit conversions across an equal sign. There is a case sensitive comparison, but no type strict comparison yet. A feature request could be posted for _ArraySearch that implements a custom "equals" that compares type as well as value. Edited July 29, 2014 by Richard Robertson 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