User Tools

Site Tools


using_20data_20statements_20in_20libraries

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
using_20data_20statements_20in_20libraries [2018/03/31 13:19] – external edit 127.0.0.1using_20data_20statements_20in_20libraries [2024/01/05 00:21] (current) – external edit 127.0.0.1
Line 2: Line 2:
  
 //by Richard Russell, March 2011//\\ \\  Because you cannot use **line numbers** or **labels** in libraries (or other [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin5.html#install|INSTALLed]] modules), the conventional forms of the [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin7.html#restore|RESTORE]] statement cannot be used. At first sight it might appear that this precludes the use of [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin4.html#data|DATA]] statements in libraries, but in fact they can be used by means of the //relative// version **RESTORE +**.\\ \\  For example the following code could be placed in a library:\\  //by Richard Russell, March 2011//\\ \\  Because you cannot use **line numbers** or **labels** in libraries (or other [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin5.html#install|INSTALLed]] modules), the conventional forms of the [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin7.html#restore|RESTORE]] statement cannot be used. At first sight it might appear that this precludes the use of [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin4.html#data|DATA]] statements in libraries, but in fact they can be used by means of the //relative// version **RESTORE +**.\\ \\  For example the following code could be placed in a library:\\ 
 +<code bb4w>
         DEF PROCrestore         DEF PROCrestore
         RESTORE +1         RESTORE +1
Line 7: Line 8:
         DATA Here,are,some,data,items,in,a,library         DATA Here,are,some,data,items,in,a,library
         DATA Here,is,some,more,data         DATA Here,is,some,more,data
 +</code>
 Calling **PROCrestore** moves the data pointer so that the next items to be [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin7.html#read|READ]] will be taken from the subsequent DATA statements:\\  Calling **PROCrestore** moves the data pointer so that the next items to be [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin7.html#read|READ]] will be taken from the subsequent DATA statements:\\ 
 +<code bb4w>
         PROCrestore         PROCrestore
         READ A$,B$,C$,D$         READ A$,B$,C$,D$
 +</code>
 (this code could be in the main program or in a library).\\ \\  Note the use of **RESTORE +1** rather than **RESTORE +2**, as might superficially seem more correct. This ensures that the code will work correctly even if the library is crunched using the **concatenate lines** option (resulting in the **ENDPROC** being moved onto the same line as the **RESTORE**).\\ \\  If you find that disconcerting you could always move the **ENDPROC** until after the **DATA** statements:\\  (this code could be in the main program or in a library).\\ \\  Note the use of **RESTORE +1** rather than **RESTORE +2**, as might superficially seem more correct. This ensures that the code will work correctly even if the library is crunched using the **concatenate lines** option (resulting in the **ENDPROC** being moved onto the same line as the **RESTORE**).\\ \\  If you find that disconcerting you could always move the **ENDPROC** until after the **DATA** statements:\\ 
 +<code bb4w>
         DEF PROCrestore         DEF PROCrestore
         RESTORE +1         RESTORE +1
Line 16: Line 21:
         DATA Here,is,some,more,data         DATA Here,is,some,more,data
         ENDPROC         ENDPROC
 +</code>
using_20data_20statements_20in_20libraries.1522502389.txt.gz · Last modified: 2024/01/05 00:16 (external edit)