Feature request: CLOSE ALL
#1
There is a trick to use the OPEN command to test whether a file exists. The problem with that is that you need to guess at which stream was opened and close it, otherwise you'll get a "stream already in use error" further down the line. A CLOSE ALL command would be a useful way to solve that problem.

In fact, leaving streams open indefinitely is a bad idea anyway. Occasionally you may want to read from one file and write to another, but even then, I prefer to read data into a variable or array, close the stream and then write it to a new one. CLOSE ALL woild make our programs a little more robust.

Yes, you could fake it with a for ... next loop. Having such a command in yab itself would be faster.
Reply
#2
In yab, one cannot open a file without knowing the stream number. I admit that a CLOSE ALL, or just CLOSE might be a good thing. I will look at the code and see if my c++ knowledge is good enough to make it happen.
Reply
#3
To be more precise, I am seeing this with

Code:
IF OPEN(pathname$, "r") THEN ...

which is a useful way to test for the existence of a file. This seems to be the only variation of OPEN that does not require a stream number. But it still requires the stream to be closed afterwards.

I suppose you could use SYSTEM("test -e " + pathname$) but the less we need to shell out, the better

If I've been careful with my streams, it will grab the first available one, normally #1, and CLOSE#1 will get rid of it. But If you have not been careful, well ...

BTW, when I was writing "Programming with yab", I noticed that our documentation does not explicitly mention how many streams are available, so I started increasing the number until I got an error. I was expecting 9, like in QuickBasic. In fact, it is 124. How insane is that? I'd really hate to maintain the program that had 124 files open.
Reply
#4
Code:
handle=OPEN(pathname$, "r")
if handle then...

close handle

Angel
Reply
#5
Aha, that does solve the problem. Thanks.
Reply
#6
I added the option to close all files: https://github.com/bbjimmy/YAB/commit/20...6156cb9a6f

close -2 closes all open files....

or

all=-2
close all

Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)
Free Web Hosting