DIM info
AS STRING * 100, inpt
AS STRING * 100 'one string to write data, one string to read data.
info = "foo"
PUT #1, 1, info
'and put 3 pieces of data in it, in record #1 info = "poo"
PUT #1, 2, info
'in record #2 info = "shoo a shoo a boo"
PUT #1, 3, info
'in record #3
GET #1, 1, inpt
'And let's get and print those records, starting at #1 GET #1, 2, inpt
'record #2 GET #1, 3, inpt
'record #3
OPEN "temp.txt" FOR BINARY AS #1 'Now, to show that BINARY does the exact same thing... filesize = 100
record_number = 1
GET #1, filesize
* (record_number
- 1) + 1, inpt
'And let's get and print those records, starting at #1 record_number = 2
GET #1, filesize
* (record_number
- 1) + 1, inpt
'#2 record_number = 3
GET #1, filesize
* (record_number
- 1) + 1, inpt
'#3
'now, that might seem a little complex from the above, but that's only because I wanted to show the
'formula which you'd use to calculate the offset of each file's position.
'usually, you'd use something much simpler like the following:
info = "Potato Chips"
info = "Root Beer"
info = "Cheese"
'And to show that our data is still interchangeable, I'm going to use RANDOM access to get and print it
GET #1, 1, inpt
'And let's get and print those records, starting at #1 GET #1, 2, inpt
'record #2 GET #1, 3, inpt
'record #3
'So, as you can see, BINARY and RANDOM really aren't that different. The only real change is that
'you have to calculate the offset yourself, rather than just reference a record number.
'And that caculation is rather simple:
'(Recordnumber - 1) * RecordLength + 1
'Our first record always starts at Byte 1...
'Every record after that increases by the record length in size. (in this case 100)
'so 001, 101, 201, 301, 401, 501, 601 are the positions of the first 7 records.