Public Sub BinarySearch_Surname(ByVal BrownieArray() As Brownie_Structure, ByVal SearchItem As String, ByVal LowInt As Integer, ByVal HighInt As Integer)
Dim ItemFound As Boolean = False
Dim SearchFailed As Boolean = False
Dim Midpoint As Integer = Int((LowInt + HighInt) / 2)
Try
If BrownieArray(Midpoint).Surname = SearchItem Then
ItemFound = True
Else
If LowInt >= HighInt Then
SearchFailed = True
Else
If BrownieArray(Midpoint).Surname < SearchItem Then
**BinarySearch_Surname(BrownieArray, Midpoint + 1, HighInt, ItemFound)
Else
BinarySearch_Surname(BrownieArray, LowInt, Midpoint - 1, HighInt)**
End If
End If
End If
If SearchFailed = True Then
MessageBox.Show("Failed to find Suranme in database", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If ItemFound = True Then
MessageBox.Show("Surname: " & BrownieArray(Midpoint).Surname, "Found", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
Catch
MessageBox.Show("Failed to find , please insert correct infomation and try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Exit Sub
End Try
End Sub
StackOverflow occurs with this recursive algorithm, I know why the error is caused but do not know how to fix it?
This line:
Should be:
This line:
Should be:
This line:
Should be: