BBC BASIC for Windows
Programming >> Database and Files >> The Most Basic READ and WRITE DATA LESSON EVER!!
http://bb4w.conforums.com/index.cgi?board=database&action=display&num=1457928203

The Most Basic READ and WRITE DATA LESSON EVER!!
Post by michael on Mar 14th, 2016, 04:03am

I have simplified this as much as I can..
Now even the most Novice beginner should be able to store and retrieve data easily..
Although this wasn't my intended plan, I guess I don't want to reinvent the entire wheel !
When I first started learning programming this is the style of lessons I saw..

And in 1982 I thought space bar had something to do with gaming, even though I didn't have any games at the time.
Programming was my game (self taught)

The program is easier to understand once it is in the BBC editor
Code:
      REM THE SIMPLEST FILE DATA MANAGEMENT EXAMPLE ON THIS FORUM !!
      REM OPEN A FILE FOR OUTPUT AND WRITE 4 DIFFRENT PIECES OF DATA (Even if it doesnt look like it)
      A=OPENOUT(@usr$+"JUNK.DAT")
      REM The next command line will write 3 strings and 1 number to the file*******
      REM VVVVV notice how A becomes #A as an identifier or device handle FOR THE FILE YOU MAKE***
      PRINT#A,"REALLY?","THERE ARE",4,"DATA SECTIONS TO THIS DATA"
      CLOSE#A
      REM OPEN A FILE AND READ THE CONTENTS AND PRINT THEM ON THE SCREEN
      A=OPENIN(@usr$+"JUNK.DAT")
      REM VVVVV notice how A becomes #A as an identifier or device handle FOR THE FILE YOU READ***
      INPUT#A,A$,B$,N,C$
      PRINT A$;" ";B$;" ";N;" ";C$
      REM ^^^^^^ The read must be the same as the written file for accuracy ^^^^^
      REM break down the elements of the data so they can see
      PRINT
      PRINT "1 ";A$
      PRINT "2 ";B$
      PRINT "3 (this is not a string) -";N
      PRINT "4 ";C$
 CLOSE#A    
 END
 

Re: The Most Basic READ and WRITE DATA LESSON EVER
Post by Zaphod on Mar 14th, 2016, 04:44am

Code:
REM VVVVV notice how A becomes #A 


The # is really part of the file keywords like INPUT# and BB4W lets you put a space between the INPUT and the # but the # is not in any way a prefix of the variable name as you implied. The # is telling the program that the input is not coming from the keyboard but from some other channel, in this case the filing system.
Re: The Most Basic READ and WRITE DATA LESSON EVER
Post by michael on Mar 14th, 2016, 04:53am

I can only relate it to a device, as I am comparing its usage to my previous platform..
Normally #1 or #a ect would have meant a device handle

A window or text box or graphics screen would require a device handle such as #f or #1 or #2 or whatever you wanted.

Thanks for letting me know that the file handle ---- A was not changed..



Re: The Most Basic READ and WRITE DATA LESSON EVER
Post by Zaphod on Mar 14th, 2016, 05:38am

You can show that the # is not part of the variable in BB4W if you put in things like INPUT # (A) or INPUT# (2*A/2)
What comes after the # only has to be something that evaluates to a channel number. This may well be different to other dialects of BASIC.