Problem re-reading a file

Post Reply
User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Problem re-reading a file

Post 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.
The only thing that gets me down is gravity...

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Problem re-reading a file

Post 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.
The only thing that gets me down is gravity...

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Problem re-reading a file

Post 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

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Problem re-reading a file

Post 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.
The only thing that gets me down is gravity...

Post Reply