Thanks for the examples Steve. That gives me something I can wrap my head around. So if I'm understanding this right, it can work with variable length data so long as that data is read back in the proper sequence, since it retains a pointer off the last PUT/GET operation. I'm interested in getting multiple user defined type array stuff consolidated into fewer files.
For variable length data, the easiest implementation is to write LENGTH, then DATA.
OPEN "Temp.txt" FOR BINARY AS #1
A$ = "Whatever you want, of any length."
L = LEN(A$)
PUT #1, , L 'put the length
PUT #1, , A$ 'put the data
CLOSE
Then when you want to read it back, you use that information to get what you need:
OPEN "Temp.txt" FOR BINARY AS #1
GET #1, , L 'get the length
A$ = SPACE$(L) 'set a blank string to the length of the data you want to retrieve
GET #1, , A$ 'get the data
CLOSE
Without any values in the 2nd parameter of a GET statement, the command will get from the next byte in an open file, telling it where to START getting data, and the length of the data type in the 3rd parameter tells it HOW MUCH data to retrieve.
GET #1, , x% <--- Get from the next byte of the file, 2 bytes (an integer)
GET #1, , Y& <--- Get from the next byte of the file, 4 bytes (a long)
GET #1, , A$ <--- Get from the next byte of the file, whatever the LEN(A$) is.
If A$ = "", then you'll get nothing from the file. With fixed-length strings, it's not something you have to worry about as the size is always set (DIM A AS STRING * 3), but it does matter for variable-length data.
User Defined Types generally work perfect with BINARY mode, as they have a permanent, set size.
TYPE Foo
bar AS INTEGER
cheese_fingers AS STRING * 10
wang AS LONG
END TYPE
DIM example AS Foo
Just by looking at the above, you can tell every record is going to be a set length of 16 bytes (2 for the integer, 10 for the string, 4 for the long). All you'd have to do with it is:
GET #1, , example 'or PUT
It's only when dealing with variable-width data that you need to store the length with it.