ArrayList: BinarySearchEx |
Searches the entire sorted ArrayList for an element using the specified comparer and returns the zero-based index of the element.
Public Function BinarySearchEx( ByVal Index As Long, ByVal Count As Long, ByRef Value As Variant, Optional ByVal Comparer As IComparer ) As Long
The search assumes the ArrayList is sorted.
The default comparison method requires the values to be of the same intrinsic Visual Basic datatype. A vbLong will fail to compare against a vbInteger, for instance. Objects must implement the IComparable interface or an exception will be thrown.
The comparison behaviour can be overridden by supplying a custom IComparer compatible object.
If the return value is negative, then the value was not found in the list. To determine where the value should have been found, negate (Not) the return value.
Exception | Condition |
---|---|
ArgumentException |
Index and Count do not denote a valid range in the ArrayList. -or- Comparer is Nothing and neither Value nor the elements of ArrayList implement the IComparer interface. |
InvalidOperationException | Comparer is Nothing and Value is not of the same type as the elements of the ArrayList. |
ArgumentOutOfRangeException |
Index is less than zero. -or- Count is less than zero. |