12-18-2022, 12:08 AM
@Dimster All FREEFILE does is give you the next available file handle. That's it, in a nutshell. Nothing more, nothing less.
So let's say the next available file handle is 1.
x = FREEFILE <-- it's 1.
y = FREEFILE <-- it's still 1. Sure, we reported that handle to X, but we haven't used it yet. It's still available.
z = FREEFILE <-- it's still 1. Sure, we reported that handle to X and Y, but we haven't used it yet. It's still available.
OPEN "temp.txt" FOR BINARY AS #x <-- Now here, we used that file handle #1 (x = 1, after all).
OPEN "temp2.txt" FOR BINARY AS #y <-- This is going to error out. y is 1, and handle 1 is already opened. We can't have two files with the same handle opened at the same time!!
a = FREEFILE <-- this is now 2. File handle 1 is in use with "temp.txt" and X. 2 is now our latest free file handle.
CLOSE x <-- we just closed "temp.txt" and freed up file handle 1. (x = 1, after all)
b = FREEFILE <-- and this is now 1. File handle 1 has been freed, it's available for use again, so we recycle it back to b.
So, if you followed that, you can see -- all FREEFILE does is give us the next available file handle. Until you use the handle it gives you, it's still available.
The way you'd use it with your code would be:
DataDay1 = FreeFile
Day1$ = Str$(Day1)
Open FileName$+LTrim$(Day1$) as #DataDay1
DataDay2 = FreeFile
Day2$ = Str$(Day2)
Open FileName$+LTrim$(Day2$) as #DataDay2
So let's say the next available file handle is 1.
x = FREEFILE <-- it's 1.
y = FREEFILE <-- it's still 1. Sure, we reported that handle to X, but we haven't used it yet. It's still available.
z = FREEFILE <-- it's still 1. Sure, we reported that handle to X and Y, but we haven't used it yet. It's still available.
OPEN "temp.txt" FOR BINARY AS #x <-- Now here, we used that file handle #1 (x = 1, after all).
OPEN "temp2.txt" FOR BINARY AS #y <-- This is going to error out. y is 1, and handle 1 is already opened. We can't have two files with the same handle opened at the same time!!
a = FREEFILE <-- this is now 2. File handle 1 is in use with "temp.txt" and X. 2 is now our latest free file handle.
CLOSE x <-- we just closed "temp.txt" and freed up file handle 1. (x = 1, after all)
b = FREEFILE <-- and this is now 1. File handle 1 has been freed, it's available for use again, so we recycle it back to b.
So, if you followed that, you can see -- all FREEFILE does is give us the next available file handle. Until you use the handle it gives you, it's still available.
The way you'd use it with your code would be:
DataDay1 = FreeFile
Day1$ = Str$(Day1)
Open FileName$+LTrim$(Day1$) as #DataDay1
DataDay2 = FreeFile
Day2$ = Str$(Day2)
Open FileName$+LTrim$(Day2$) as #DataDay2