Jump to content

_ArraySearch Finds "BigString" inside a '0'


 Share

Recommended Posts

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

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

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

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
Link to comment
Share on other sites

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 by LeCarre
Link to comment
Share on other sites

"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 by Richard Robertson
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...