Jump to content
Sign in to follow this  
LeCarre

_ArraySearch Finds "BigString" inside a '0'

Recommended Posts

LeCarre

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)

Share this post


Link to post
Share on other sites
JohnOne

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.

Share this post


Link to post
Share on other sites
LeCarre

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.

Share this post


Link to post
Share on other sites
eukalyptus

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
  • Like 1

Share this post


Link to post
Share on other sites
LeCarre

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.

Share this post


Link to post
Share on other sites
LeCarre

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

Share this post


Link to post
Share on other sites
Richard Robertson

"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

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  

×