PDA

Click to See Complete Forum and Search --> : Reading and Writing Binary File (+ Records)


omarswan
Jan 15th, 2000, 06:18 PM
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
omarswan@yahoo.com
http://www.omarswan.cjb.net
To God Be The Glory

smalig
Jan 15th, 2000, 08:51 PM
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
smalig@hotmail.com
http://vbcode.webhostme.com/