|
-
Oct 18th, 2005, 04:13 AM
#7
New Member
Re: finding and going to a particular record in a dataset?
Here is an improved version of the previous code: -
Public Function BinarySearchRecord(ByVal ds As DataSet, ByVal intMinValue As Integer, ByVal intMaxValue As Integer, ByVal strTableName As String, ByVal strFieldName As String, ByVal strSearchValue As String) As Integer
Dim intMiddle As Integer
intMiddle = (intMinValue + intMaxValue) / 2
If intMinValue <= intMaxValue Then
If ds.Tables(strTableName).Rows(intMinValue).Item(strFieldName) = strSearchValue Then
BinarySearchRecord = intMinValue
ElseIf ds.Tables(strTableName).Rows(intMaxValue).Item(strFieldName) = strSearchValue Then
BinarySearchRecord = intMaxValue
ElseIf BinarySearchRecord(ds, (intMinValue + 1), intMiddle, strTableName, strFieldName, strSearchValue) <> -1 Then
BinarySearchRecord = BinarySearchRecord(ds, (intMinValue + 1), intMiddle, strTableName, strFieldName, strSearchValue)
ElseIf BinarySearchRecord(ds, (intMiddle + 1), (intMaxValue - 1), strTableName, strFieldName, strSearchValue) <> -1 Then
BinarySearchRecord = BinarySearchRecord(ds, (intMiddle + 1), (intMaxValue - 1), strTableName, strFieldName, strSearchValue)
Else
BinarySearchRecord = -1
End If
Else
BinarySearchRecord = -1
End If
End Function
Thomas
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|