BBC BASIC
« Re: NEW: file exists tool. Non windows based. »

Welcome Guest. Please Login or Register.
Mar 31st, 2018, 10:44pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Cross-platform BBC BASIC (Windows, Linux x86, Mac OS-X, Android, iOS, Raspberry Pi)
BBC BASIC Resources
BBC BASIC Help Documentation
BBC BASIC for Windows Home Page
BBC BASIC Programmers' Reference
BBC BASIC Beginners' Tutorial
BBC BASIC for SDL 2.0 Home Page
BBC BASIC Discussion Group

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Re: NEW: file exists tool. Non windows based.  (Read 686 times)
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 803
cheesy 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.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 803
cheesy 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.
« Last Edit: Jun 13th, 2016, 11:44am by Richard Russell » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls