Post Reply 
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Feature request: CLOSE ALL
04-15-2017, 11:08 PM
Post: #1
Feature request: CLOSE ALL
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.
Visit this user's website Find all posts by this user
Quote this message in a reply
04-16-2017, 01:22 AM
Post: #2
RE: Feature request: CLOSE ALL
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.

Fat Elk Sortware
Visit this user's website Find all posts by this user
Quote this message in a reply
04-16-2017, 07:46 PM
Post: #3
RE: Feature request: CLOSE ALL
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.
Visit this user's website Find all posts by this user
Quote this message in a reply
04-18-2017, 12:55 AM
Post: #4
RE: Feature request: CLOSE ALL
Code:
handle=OPEN(pathname$, "r")
if handle then...

close handle

Angel

Fat Elk Sortware
Visit this user's website Find all posts by this user
Quote this message in a reply
04-18-2017, 04:35 PM
Post: #5
RE: Feature request: CLOSE ALL
Aha, that does solve the problem. Thanks.
Visit this user's website Find all posts by this user
Quote this message in a reply
07-08-2017, 06:41 AM (This post was last modified: 07-08-2017 10:04 AM by bbjimmy.)
Post: #6
RE: Feature request: CLOSE ALL
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

Fat Elk Sortware
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)

Free Web Hosting