Page 1 of 1
Problem re-reading a file
Posted: Tue Apr 26, 2016 2:59 pm
by rbytes
I am creating a database that saves to a data file using FILE N$ WRITELINE X and reads from it using FILE N$ READLINE X. Everything works well the first time I read the data file, but if I try to read it again, I get empty strings. The documentation says that the file pointer is relevant for these commands, but if I try to set the pointer back to the start before reading or writing, with FILE N$ SETPOS 1, this crashes my program every time.
Re: Problem re-reading a file
Posted: Tue Apr 26, 2016 3:04 pm
by rbytes
Just on a hunch, I tried again with FILE N$ SETPOS 0. For some reason this works, but I don't understand why. My file exists, it has many lines of content. Why did a value of 1 crash my program? I have the command OPTION BASE 1 near the start of my code.
Re: Problem re-reading a file
Posted: Tue Apr 26, 2016 4:07 pm
by Mr. Kibernetik
I do not encounter any errors. For example, this code works fine:
Code: Select all
n$="test.txt"
LOOP: DO
FILE n$ READLINE t$
PRINT t$
UNTIL t$=""
PAUSE 1
FILE n$ SETPOS 1
GOTO LOOP
Re: Problem re-reading a file
Posted: Wed Apr 27, 2016 2:40 pm
by rbytes
I will have to do some more testing. I think I might have tried to read beyond the end of the file. But wouldn't this just give an error message? I got an out-of-memory crash back to the icon screen. I'll see if I can duplicate this in a code snippet.