When opening a file for RANDOM access, the given record length is ignored and the default value of 128 is used.
Test case (assumes there is no file of that name already):
10 OPEN "test.txt" FOR RANDOM AS #1 LEN=1:PUT #1:CLOSE 1
The file is now 128 bytes in size, instead of the expected 1 byte:
$ ls -l TEST.TXT
-rw-rw-r-- 1 bj bj 128 Jun 26 13:04 TEST.TXT
How I stumbled upon this? Someone at Stack Overflow asked how to write (text) files without the Ctrl+Z character at the end:
10 FILENAME$="test.txt"
20 REM Delete any old content.
30 OPEN FILENAME$ FOR OUTPUT AS #1:CLOSE 1:KILL FILENAME$
40 REM Open file in random mode with record length of 1 and assign a field to C$.
50 OPEN FILENAME$ FOR RANDOM AS #1 LEN=1:FIELD #1,1 AS C$
60 TEXT$="Hello, World!"+CHR$(13)
70 REM Now PUT each character/byte into the file one by one.
80 FOR I%=1 TO LEN(TEXT$):LSET C$=MID$(TEXT$,I%,1):PUT #1:NEXT
90 CLOSE 1
PC-BASIC Version: 2.0.4
When opening a file for RANDOM access, the given record length is ignored and the default value of 128 is used.
Test case (assumes there is no file of that name already):
The file is now 128 bytes in size, instead of the expected 1 byte:
How I stumbled upon this? Someone at Stack Overflow asked how to write (text) files without the Ctrl+Z character at the end: