Jump to content

_ArrayBinarySearch Not finding value?


Go to solution Solved by Nine,

Recommended Posts

image.png.adc5ce088e35c6752caa53d73d47ac5c.png

Can someone explain why is the 96 not found? 
Says Error code 2, which is value outside of array min/max, but clearly is not.


Column 0 is sorted, ideally I want to ignore all other columns, but the default values for optional parameters for _ArrayBinarySearch is 0. I think this should be "-1", because I dont want to search every column when specifying 0 in $iColumn. 
I want to ONLY search column 0, but I guess setting Column 0 just makes it search every column instead?

image.png.6a54fd68e1afbef76fd78b96f5718d59.png

 

Link to comment
Share on other sites

  • Solution

Maybe because the value included in the array are strings not numbers ?

ps.  please provide a runable script as you should know by now.  A picture doesn't help any bit.  Try to make it easy for us to help you

Link to comment
Share on other sites

35 minutes ago, Nine said:

Maybe because the value included in the array are strings not numbers ?

...and if $vValue (2nd parameter of _ArrayBinarySearch) is a string too, then we got OP's error 2, for example :

#include <Array.au3>
#include <MsgBoxConstants.au3>

Local $avArray[3]
$avArray[0] = "64"
$avArray[1] = "96"
$avArray[2] = "150"

_ArrayDisplay($avArray, "$avArray ")

Local $iKeyIndex = _ArrayBinarySearch($avArray, "96")
If Not @error Then
    MsgBox($MB_TOPMOST, 'Entry found', ' Index: ' & $iKeyIndex)
Else
    MsgBox($MB_TOPMOST, 'Entry Not found', ' Error: ' & @error)
EndIf

I just tested the 4 possible combinations :
* Strings in array + String in $vValue => error 2 (that's the example above)
* Strings in array + Number in $vValue : found (no error)
* Numbers in array  + String in $vValue : found (no error)
* Numbers in array  + Number in $vValue : found (no error)

3 hours ago, MaximusCZ said:

I guess setting Column 0 just makes it search every column instead?

I don't think so, _ArrayBinarySearch never searches in several columns. Column parameter set to 0 (last optional parameter of _ArrayBinarySearch) will search only in column 0 (according to the code found in Array.au3)

Link to comment
Share on other sites

18 hours ago, Nine said:

Maybe because the value included in the array are strings not numbers ?

Oh my god, now that wouldn't occur to me in a long while, that must be it. Funny how at least one, search term or array element, must be Number, but not both.

17 hours ago, pixelsearch said:

I don't think so, _ArrayBinarySearch never searches in several columns. Column parameter set to 0 (last optional parameter of _ArrayBinarySearch) will search only in column 0 (according to the code found in Array.au3)

Ah, then I guess it's just not consistent with other functions that default to -1, but I am okay with that.

 

Thank you both!

 

Edit: Yes, specifying the $time to Number($time) started returning search results OK!

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