11
QB64 Discussion / Re: SEEK # or not SEEK #
« Last post by SMcNeill on April 15, 2022, 02:47:14 pm »The # is optional in the SEEK statement.
SEEK #52, 1
is the same thing as
SEEK 52, 1
Think of it as being similar to the LET statement. :)
And Seek works for all our modes -- it just works differently in RANDOM.
Let's say I have a data file that looks like:
ABCDEFGHIJKLMNO
16 bytes in that data file, correct? (A to O is the file)
Now, if we OPEN thatfile FOR Input, Output, or Binary....
SEEK thatfile, 3 <-- this just moved our file marker to being in front of the third byte -- the "C".
Now, if we OPEN thatfile FOR Random ... LEN = 4
SEEK thatfile, 3 <-- this just moved the file marker to being in front of the third RECORD -- the "I". (Since we set our record size as being 4 bytes. Record 1 is ABCD. Record 2 is EFGH. The start of record three is before the "I".)
Seek, with Random files works by records. With everything else, it works by byte position.
SEEK #52, 1
is the same thing as
SEEK 52, 1
Think of it as being similar to the LET statement. :)
And Seek works for all our modes -- it just works differently in RANDOM.
Let's say I have a data file that looks like:
ABCDEFGHIJKLMNO
16 bytes in that data file, correct? (A to O is the file)
Now, if we OPEN thatfile FOR Input, Output, or Binary....
SEEK thatfile, 3 <-- this just moved our file marker to being in front of the third byte -- the "C".
Now, if we OPEN thatfile FOR Random ... LEN = 4
SEEK thatfile, 3 <-- this just moved the file marker to being in front of the third RECORD -- the "I". (Since we set our record size as being 4 bytes. Record 1 is ABCD. Record 2 is EFGH. The start of record three is before the "I".)
Seek, with Random files works by records. With everything else, it works by byte position.