CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2001
    Location
    Dallas, TX
    Posts
    9

    Random Access Files

    I have a file I'm trying to access randomly. the only problem is that I have a record header at the beginning that is not the same length as the other records. Is there a way when writing to this file to tell it to write to fifth file but add in the offset of 64 bytes to account for the record header?


  2. #2
    Join Date
    Aug 2000
    Location
    Ottawa, Canada
    Posts
    469

    Re: Random Access Files

    As I understand you have file of records (with static size) and this file also has a header.
    So:
    You know the size of your header = A
    You know the size of each record = B

    Now to read/write any record R you do:

    ' open file
    Open "C"\MyFile.dat" for binary Access Read Write lock Read Write as #1
    '...
    ' set position
    seek #1, (A + (B * R))
    ' read by get() or Write by Put() functions





  3. #3
    Join Date
    Aug 2001
    Location
    Dallas, TX
    Posts
    9

    Re: Random Access Files

    Thanks for the help. That did the trick. I can't believe I haven't heard or read of this yet. I've been trying to figure this out for days and the answer is so simple.
    Thanks again.


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

Featured