Problem re-reading a file
- 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:
- Contact:
Problem re-reading a file
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...
- 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:
- Contact:
Re: Problem re-reading a file
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...
- Mr. Kibernetik
- Site Admin
- Posts: 4786
- Joined: Mon Nov 19, 2012 10:16 pm
- My devices: iPhone, iPad, MacBook
- Location: Russia
- Flag:
Re: Problem re-reading a file
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
- 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:
- Contact:
Re: Problem re-reading a file
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...