Results 1 to 4 of 4

Thread: Searching record on random access file

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Location
    Annandale
    Posts
    6

    Post

    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?

  2. #2
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Gig Harbor, WA; Posts: 89950
    Posts
    360
    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

  3. #3
    Hyperactive Member Pix's Avatar
    Join Date
    Feb 2001
    Location
    I'm not telling you (or them)
    Posts
    282
    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

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Location
    Annandale
    Posts
    6
    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
  •  



Click Here to Expand Forum to Full Width