2Pac
04-16-2004, 11:13 AM
HELP!! Ive tried to do a binary search on the following Access Database through Data1.recordset.
I think that only one line of code needs to be changed: how to specify a Long Variable type to equal the first record in the database.
Its highlighted in red below, I think this is all that needs to be changed, but am not sure.....
Option Explicit
Dim db As Database
Dim rs As Recordset
Private Sub Command1_Click()
Dim hit As Boolean, fTop As Long
Dim fBott As Long, fTmp As Long
If txtSearch.Text = "" Then
MsgBox "Nothing to do."
txtSearch.SetFocus
Exit Sub
End If
hit = False
fTop = Data1.Recordset.RecordCount - 1
fBott = 0
fTmp = (fTop + fBott) / 2
Do While (Not hit) And (fTop >= fBott)
Data1.Recordset. = fTmp
'WHAT DO I PUT IN HERE TO MAKE fTmp = FIRST RECORD ??
If Data1.Recordset("Staff Number") = txtSearch.Text Then
hit = True
ElseIf Text1.Text < Data1.Recordset("Staff Number") Then
fTop = fTmp - 1
Else
fBott = fTmp + 1
End If
fTmp = (fTop + fBott) / 2
If Not hit Then
MsgBox "No match"
Else
txtSurname.Text = Data1.Recordset("Surname")
End If
Loop
txtSearch.SetFocus
End Sub
I think that only one line of code needs to be changed: how to specify a Long Variable type to equal the first record in the database.
Its highlighted in red below, I think this is all that needs to be changed, but am not sure.....
Option Explicit
Dim db As Database
Dim rs As Recordset
Private Sub Command1_Click()
Dim hit As Boolean, fTop As Long
Dim fBott As Long, fTmp As Long
If txtSearch.Text = "" Then
MsgBox "Nothing to do."
txtSearch.SetFocus
Exit Sub
End If
hit = False
fTop = Data1.Recordset.RecordCount - 1
fBott = 0
fTmp = (fTop + fBott) / 2
Do While (Not hit) And (fTop >= fBott)
Data1.Recordset. = fTmp
'WHAT DO I PUT IN HERE TO MAKE fTmp = FIRST RECORD ??
If Data1.Recordset("Staff Number") = txtSearch.Text Then
hit = True
ElseIf Text1.Text < Data1.Recordset("Staff Number") Then
fTop = fTmp - 1
Else
fBott = fTmp + 1
End If
fTmp = (fTop + fBott) / 2
If Not hit Then
MsgBox "No match"
Else
txtSurname.Text = Data1.Recordset("Surname")
End If
Loop
txtSearch.SetFocus
End Sub