So, related to the "bug" (I'm don't sure if it's one) i wrote about in http://vbforums.com/showpost.php?p=2019158&postcount=3 ,

here's an example about what I mean.

I am using the normal function ArrBinarySearch, but just with 2 lines added for debugging.

VB Code:
  1. Private Function ArrBinarySearch(ByRef sArray() As String, _
  2.                                  ByRef sSearch As String, _
  3.                                  ByVal lFirst As Long, _
  4.                                  ByVal lLast As Long, _
  5.                                  Optional ByVal Compare As VbCompareMethod = vbBinaryCompare) As Long
  6.    
  7.     Dim lMid    As Long
  8.     Dim lStrC   As Long
  9.    
  10.     On Error Resume Next
  11.    
  12.     If lFirst = lLast Then
  13.         ArrBinarySearch = lFirst
  14.     Else
  15.        
  16.         lMid = (lFirst + lLast) \ 2         '<-- ###########
  17. [b]        MsgBox " "
  18.         Debug.Print "lFirst: " & lFirst & "  lLast: " & lLast & "  -->  lMid: " & lMid[/b]
  19.        
  20.         lStrC = StrComp(sSearch, sArray(lMid), Compare)
  21.        
  22.         Select Case lStrC
  23.             Case -1
  24.                 ArrBinarySearch = ArrBinarySearch(sArray(), sSearch, lFirst, lMid)
  25.             Case 0
  26.                 ArrBinarySearch = lMid
  27.             Case 1
  28.                 ArrBinarySearch = ArrBinarySearch(sArray(), sSearch, lMid, lLast)
  29.         End Select
  30.     End If

This one is now called by the function SearchArray, because the element i'll search for, isn't the first or the last one.

I'm calling SearchArray with
VB Code:
  1. lResult = SearchArray(asMessageData(), sMessageData, vbTextCompare)

where asMessageData is the Array i've stored some Text of Mails and sMessageData is an new Mail, where i want to check if this one already exists.

This Array has an LBound of 1, and in this case, where it ends in an endless loop, the UBound of 4.
Bevore, this also happend when my UBound was 35, and all other Values after 4 chr(0).

Here's the Debug Output from the Line i've added above.
Code:
neu
neu
neu
lFirst: 1  lLast: 4  -->  lMid: 2
lFirst: 1  lLast: 2  -->  lMid: 1
lFirst: 1  lLast: 2  -->  lMid: 1
lFirst: 1  lLast: 2  -->  lMid: 1
lFirst: 1  lLast: 2  -->  lMid: 1
lFirst: 1  lLast: 2  -->  lMid: 1
lFirst: 1  lLast: 2  -->  lMid: 1
lFirst: 1  lLast: 2  -->  lMid: 1
"Neu" means, i've got a new mail, this includes that the search function has passed without any errors.

In the 4th case, as you see, it always returns to the value 1.
Don't know how to fix this

lg, freescale