Results 1 to 2 of 2

Thread: Reading and Writing Binary File (+ Records)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    NY, USA.
    Posts
    240

    Post

    could someone sho me how to read and write to a binary files using as example the record structure below:

    Type Record
    FirstName As String
    LastName As String
    pin As String
    email As String
    End Type

    also could you show how to detect .EOF and .BOF



    ------------------
    OmarSwan
    [email protected]
    http://www.omarswan.cjb.net
    To God Be The Glory

  2. #2
    Addicted Member
    Join Date
    Oct 1999
    Posts
    232

    Post

    You must be used Random access for Open statement and Get/Put commands.

    For sample:

    Type Record ' Define user-defined type.
    ID As Integer
    Name As String * 20
    End Type

    Dim MyRecord As Record, Position ' Declare variables.
    ' Open sample file for random access.
    Open "TESTFILE" For Random As #1 Len = Len(MyRecord)
    ' Read the sample file using the Get statement.
    Position = 3 ' Define record number.
    Get #1, Position, MyRecord ' Read third record.
    Close #1 ' Close file.

    ' Put a record.
    MyRecord.ID = RecordNumber ' Define ID.
    MyRecord.Name = "My Name" & RecordNumber ' Create a string.
    Put #1, RecordNumber, MyRecord ' Write record to file.

    And use the Seek() function for specify the current read/write position.

    ------------------
    smalig
    [email protected]
    http://vbcode.webhostme.com/



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