|
-
Mar 15th, 2001, 11:47 AM
#1
Thread Starter
New Member
How do I write a code to search for part of a specific record from random access file (e.g. LastName)
and then display the matched record on the form?
-
Mar 15th, 2001, 01:40 PM
#2
Hyperactive Member
I would use a Sequential Access File, so the search can be controlled and use an EOF command, but This may or may not work. I didn't try it.
Lee
Code:
Dim strSearchName As String
Dim strName As String
Dim intCount As Integer
Dim Found As Boolean
strSearchName = txtName.Text
Intcount = 1 'Random Files Start At 1
Open "C:\MyFile.Dat" For Random As #1
On Error Resume Next
Do Until Found = True
Get #1, intCount, strName
If strName = strSearchName Then
Found = True
lblName.Caption = strName
End If
intCount = intCount + 1
Loop
'Code improved by vBulletin Tool (Save as...)
Don't forget to add the error trap, and close the file!
 Mahalo 
VB6(SP5), VC++, COBOL, Basic, JAVA
MBA, MCSD, MCSE, A+
Computer Forensics
-
Mar 15th, 2001, 02:08 PM
#3
Hyperactive Member
I'm not sure if this is what you're looking for, but when I search through Random Access Files I do this:
Code:
Private Sub FindRecord_Click()
Dim Count As Integer
Open "c:\Myfile.dat" for Random As #1 Len=Len _ (RecordStructureName)
NoOfRecords=LOF(1)\Len(RecordStructureName)
SFLastName=InputBox("Enter Last Name")
Count=0
Found=False
While (Count<=NoOfRecords) And (Found=False)
Count=Count+1
Get #1, Count, RecordStructureName
If Trim(LastName.text)=SFLastName Then
Found=True
End If
Wend
If Found=True Then
LastName.text=RecordStructureName.LastName
'This transfers the fileds from the record stucture into text boxes
'Do this for all fields
End If
If Found=False Then
MsgBox ("Record not found in file")
Close #1
End If
End If
End Sub
If it doesn't work or you don't understand what I've written (I'm the first to admit I'm no good at explaining) let me know and I'll try to give you a better example
Pix
-
Mar 15th, 2001, 03:43 PM
#4
Thread Starter
New Member
Thanks,
I'll try to see if it works and let you know later.
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
|