Jump to content

_ArrayBinarySearch Not finding value?


Go to solution Solved by Nine,

Recommended Posts

Posted

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

 

  • Solution
Posted
Posted
  On 11/7/2024 at 12:57 PM, Nine said:

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

Expand  

...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)

  On 11/7/2024 at 9:40 AM, MaximusCZ said:

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

Expand  

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)

"I think you are searching a bug where there is no bug... don't listen to bad advice."

Posted (edited)
  On 11/7/2024 at 12:57 PM, Nine said:

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

Expand  

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.

  On 11/7/2024 at 1:38 PM, 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)

Expand  

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...