Jump to content

[Solved] ArraySearch doesn't work when using $array[0] = 0


Recommended Posts

Hello everybody, so I might found a bug in _ArraySearch:
 

#include <Array.au3>
Local $abc[2] = ["b", "b"]
$h = "+---------------------------------+" & @CRLF
ConsoleWrite($h)
For $i = 0 To 1
    $abc[0] = 0
    out()
    $abc[0] = 1
    out()
    $abc[0] = -1
    out()
    $abc[0] = "Abc"
    out()
    $abc[1] = "Hello"
Next
Func txt()
    Return "$abc = [" & $abc[0] & ", " & $abc[1] & "]" & @CRLF & _
            "> _ArraySearch($abc,""Hello"") = "
EndFunc   ;==>txt
Func shouldoutput($ans)
    Return "_ArraySearch Should return:  " & ($ans ? 1 : -1)
EndFunc   ;==>shouldoutput
Func out()
    ConsoleWrite("> " & txt() & _ArraySearch($abc, "Hello") & @CRLF & "> " & shouldoutput($abc[1] == "Hello") & @CRLF & $h)
EndFunc   ;==>out
Exit

Sorry for this messy script

Edited by algiuxas

After switching years ago to Linux, sadly I don't use AutoIt anymore.

Link to comment
Share on other sites

10 minutes ago, algiuxas said:

Hello everybody, so I might found a bug in _ArraySearch:
 

#include <Array.au3>
Local $abc[2] = ["b", "b"]
$h = "+---------------------------------+" & @CRLF
ConsoleWrite($h)
For $i = 0 To 1
    $abc[0] = 0
    out()
    $abc[0] = 1
    out()
    $abc[0] = -1
    out()
    $abc[0] = "Abc"
    out()
    $abc[1] = "Hello"
Next
Func txt()
    Return "$abc = [" & $abc[0] & ", " & $abc[1] & "]" & @CRLF & _
            "> _ArraySearch($abc,""Hello"") = "
EndFunc   ;==>txt
Func shouldoutput($ans)
    Return "_ArraySearch Should return:  " & ($ans ? 1 : -1)
EndFunc   ;==>shouldoutput
Func out()
    ConsoleWrite("> " & txt() & _ArraySearch($abc, "Hello") & @CRLF & "> " & shouldoutput($abc[1] == "Hello") & @CRLF & $h)
EndFunc   ;==>out
Exit

Sorry for this messy script

Yeah, I can't even begin to interpret what you are trying to accomplish here.  But first thing that needs to be clarified is WHICH parameter you believe is throwing the error when set to 0.  But even given that, I notice that your _Arraysearch function uses the default values in the script you provided, so I am not sure what you are saying is broken.

Link to comment
Share on other sites

Just now, MattHiggs said:

Yeah, I can't even begin to interpret what you are trying to accomplish here.  But first thing that needs to be clarified is WHICH parameter you believe is throwing the error when set to 0.  But even given that, I notice that your _Arraysearch function uses the default values in the script you provided, so I am not sure what you are saying is broken.

+---------------------------------+
> $abc = [0, b]
> _ArraySearch($abc,"Hello") = 0
> _ArraySearch Should return:  -1
+---------------------------------+
> $abc = [1, b]
> _ArraySearch($abc,"Hello") = -1
> _ArraySearch Should return:  -1
+---------------------------------+
> $abc = [-1, b]
> _ArraySearch($abc,"Hello") = -1
> _ArraySearch Should return:  -1
+---------------------------------+
> $abc = [Abc, b]
> _ArraySearch($abc,"Hello") = -1
> _ArraySearch Should return:  -1
+---------------------------------+
> $abc = [0, Hello]
> _ArraySearch($abc,"Hello") = 0
> _ArraySearch Should return:  1
+---------------------------------+
> $abc = [1, Hello]
> _ArraySearch($abc,"Hello") = 1
> _ArraySearch Should return:  1
+---------------------------------+
> $abc = [-1, Hello]
> _ArraySearch($abc,"Hello") = 1
> _ArraySearch Should return:  1
+---------------------------------+
> $abc = [Abc, Hello]
> _ArraySearch($abc,"Hello") = 1
> _ArraySearch Should return:  1
+---------------------------------+

You can see it returns incorrectly when the first array value is 0.

After switching years ago to Linux, sadly I don't use AutoIt anymore.

Link to comment
Share on other sites

  • Developers

Sometimes it would help when one first dumb things down to the basics to show their issue. ;)

Have a look at this and see if you can figure out why you get your "error":

#include <Array.au3>
Local $abc[2] = [0, 1]
ConsoleWrite('_ArraySearch($abc, "ABC") = ' & _ArraySearch($abc, "ABC") & ' >Error code: ' & @error & @CRLF)
ConsoleWrite('_ArraySearch($abc, 0) = ' & _ArraySearch($abc, 0) & ' >Error code: ' & @error & @CRLF)
ConsoleWrite('_ArraySearch($abc, 1) = ' & _ArraySearch($abc, 1) & ' >Error code: ' & @error & @CRLF)
ConsoleWrite('_ArraySearch($abc, "ABC", Default, Default, Default, 3) = ' & _ArraySearch($abc, "ABC", Default, Default, Default, 3) & ' >Error code: ' & @error & @CRLF)
ConsoleWrite('_ArraySearch($abc, 0, Default, Default, Default, 3) = ' & _ArraySearch($abc, 0, Default, Default, Default, 3) & ' >Error code: ' & @error & @CRLF)
ConsoleWrite('_ArraySearch($abc, 1, Default, Default, Default, 3) = ' & _ArraySearch($abc, 1, Default, Default, Default, 3) & ' >Error code: ' & @error & @CRLF)

Jos

Edited by 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

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

×
×
  • Create New...