CorArray: BinarySearchEx |
Searches a range of elements in a one-dimensional sorted Arr for a value, using an optionally specified IComparer interface.
Public Function BinarySearchEx( ByRef Arr As Variant, ByVal Index As Long, ByVal Length As Long, ByRef Value As Variant, Optional ByVal Comparer As IComparer ) As Long
If the returned value is less than the lower bound of the array, then
If the returned value is less than the lower bound of the array, the value is a bitwise Not indication of where the value would have been found in the array. The following shows how to convert the result for a value that is not found.
Lower Bound of Arr | Conversion Method |
---|---|
Zero | Index = Not Result |
Non-zero | Index = (Not (Result - LBound(Arr))) + LBound(Arr) |
Exception | Condition |
---|---|
ArgumentNullException | Arr is uninitialized |
RankException | Arr is multidimensional. |
ArgumentOutOfRangeException |
Index is less than the lower-bound of Arr. -or- Length is less than zero. |
ArgumentException | Value is of a type that is not compatible with the elements in Arr. |
InvalidOperationException | Value is not comparable to the elements in Arr. |