yab | yet another Basic for HAIKU
Feature request: CLOSE ALL - Printable Version

+- yab | yet another Basic for HAIKU (https://yab.orgfree.com/forum)
+-- Forum: installing / troubleshooting / feature requests (https://yab.orgfree.com/forum/forumdisplay.php?fid=5)
+--- Forum: feature requests / bug fixes (https://yab.orgfree.com/forum/forumdisplay.php?fid=11)
+--- Thread: Feature request: CLOSE ALL (/showthread.php?tid=86)



Feature request: CLOSE ALL - clasqm - 04-15-2017

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.


RE: Feature request: CLOSE ALL - bbjimmy - 04-15-2017

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.


RE: Feature request: CLOSE ALL - clasqm - 04-16-2017

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.


RE: Feature request: CLOSE ALL - bbjimmy - 04-17-2017

Code:
handle=OPEN(pathname$, "r")
if handle then...

close handle

Angel


RE: Feature request: CLOSE ALL - clasqm - 04-18-2017

Aha, that does solve the problem. Thanks.


RE: Feature request: CLOSE ALL - bbjimmy - 07-07-2017

I added the option to close all files: https://github.com/bbjimmy/YAB/commit/20854fc3b05290fa4d89e52fb25f8b6156cb9a6f

close -2 closes all open files....

or

all=-2
close all

Smile


Free Web Hosting