Author |
Topic: Re: NEW: file exists tool. Non windows based. (Read 688 times) |
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
Re: NEW: file exists tool. Non windows based.
« Thread started on: Jun 12th, 2016, 2:51pm » |
|
on Jun 12th, 2016, 2:19pm, michael wrote:| Perhaps someone would like to improve it. |
|
A 'file exists' function in BBC BASIC is straightforward:
Code: DEF FNfile_exists(f$) LOCAL F% F% = OPENIN(f$) IF F% CLOSE #F% : = TRUE = FALSE Remember that BBC BASIC has pre-defined functions TRUE and FALSE so they are the natural way of returning a Boolean condition from a function. Returning a string like "yes" or "no" is slow and wasteful of memory; perhaps it's encouraged in Liberty BASIC but it's not how one would normally do it in BBC BASIC.
Understandably, if you have previous experience of another BASIC dialect there is a tendency to design code as you would in that dialect and then 'translate' it to BBC BASIC. Often that will result in code which works, but which is wasteful or inefficient or over-complicated. In time you will hopefully learn to 'think' in BBC BASIC.
Richard.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
Re: NEW: file exists tool. Non windows based.
« Reply #1 on: Jun 13th, 2016, 11:44am » |
|
on Jun 13th, 2016, 04:47am, michael wrote:| It actually didn't come from Liberty. It came from self taught programming habits on the Trs-80 and the CoCo3 computers and on GWbasic and Qbasic. |
|
Your 'file exists' function was evidently based on a dialect of BASIC in which opening a non-existent file results in an error, which you then have to trap using ON ERROR. I had assumed that was Liberty BASIC, because it's certainly true in that dialect, but maybe it was one of the others you mention.
The key point is that in BBC BASIC attempting to open a non-existent file does not result in an error, it simply causes the relevant OPEN function to return zero. So error-trapping, plus additional code to force an error to occur (i.e. attempting to read from the file), is unnecessary.
Quote:| So soon we should see PLAYWAVE and RECORDWAVE tools. |
|
The equivalent of PLAYWAVE is of course already available; it's documented in the BB4W Help manual:
Code: SYS "PlaySound", wave$, 0, &20001 Quote:| We can make lots of tools for BBC. |
|
After nearly 15 years I would be surprised if there are many 'tools for BB4W' that don't already exist! Certainly both playing and recording WAV files are already well covered. Playing is documented in the main Help file, as above, and recording in the Wiki:
http://bb4w.wikispaces.com/Capturing+audio+using+MCI http://bb4w.wikispaces.com/Inputting+real-time+audio
Richard.
|
|
|
|
|