Results 1 to 3 of 3

Thread: Problem with random access file

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2001
    Posts
    1

    Problem with random access file

    trying to open a random access file
    but i get an record length error for no reason i am aware of

    please help if u know

  2. #2
    Megatron
    Guest
    Code:
    Open "MYFILE.FIL" For Random As #1 Len = 1000
    Put #1, recNum , data
    Close #1

  3. #3
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Random access files are good only if you know the length of each record. If yes then I would suggest using user defined data type to populate the record data with. Lets say you have a record like this:
    FirstName, LastName, Address, Phone
    Code:
    Private Type Person
        strFirstName As String * 15
        strLastName As String * 15
        strAddress As String * 25
        strPhone As String * 10
    End Type
    
    Private Sub Command1_Click()
        Dim intFFN As Integer
        Dim udtRec As Pesron
    
        intFFN = FreeFile
    
        Open "C:\MyFile.txt" For Random As intFFN Len = Len(udtRec)
    
        Do Until EOF(intFFN)
            Get #intFFN, , udtRec
            With udtRec
                Debug.Print .strFirstName & " " & .strLastName & " " & .strAddress & " " & strPhone
            End With
        Loop
    
        Close #intFFN
    End Sub

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