Bug in BASIC?
Thomas Milius (1471) 64 posts |
I am confused. I wanted to fill an array inside a BASIC library using DATA and READ command. However I am getting an “out-of-data-error”. If running the I searched inside the BASIC manuals for restrictions. Am I doing something wrong or BASIC (BB xM V5.19 10-NOV-12)? File Library:
File Main
|
Martin Bazley (331) 379 posts |
After a bit of testing, the answer to your question appears to be that the RESTORE keyword, as well as resetting the DATA pointer to the first line, also resets it to the main (non-library) BASIC file. You can confirm this by adding “DATA 3,4” to your Main file – then it doesn’t error, and prints “3”. Try this: DEF PROCInitialize LOCAL DATA RESTORE +1 DATA 1,2 READ a% PRINT a% ENDPROC |
Thomas Milius (1471) 64 posts |
Many thanks for the hint I shall try tomorrow in my original problem. However something is odd. The BASIC manual tells me that RESTORE shall set up a local DATA pointer whilst RESTORE DATA shall switch back to the original pointer (or better the stacked pointer above). I also tried a RESTORE followed by a line number which failed for me (I think I placed the DATA before the RESTORE, perhaps it works in case that data is located afterwards, but yes). Was this ever wrong, it is a bug inside the manual or is there a problem with the actual BASIC version? |
Steve Drain (222) 1620 posts |
Martin’s routine is the correct way to use a local DATA pointer. RESTORE alone always sets the DATA pointer to the value of PAGE, ie the start of the main program. It never sets up a local pointer. RESTORE lino sets the DATA pointer to a specific line number in the main program, and that line must exist. LOCAL DATA stacks the current DATA pointer and RESTORE DATA, or the end of a PROC/FN unstacks it. Remember that a LOCAL DATA statement must follow any other LOCAL statements that create local variables. RESTORE+N sets the DATA pointer to the start of the Nth line after that statement, so it can be used in libraries. Therefore, the RESTORE+ statement must come before the DATA line. I am not sure what BASIC manual you have used, but it cannot be the paper one or my StrongHelp manual, which are pretty clear how DATA works. |
Thomas Milius (1471) 64 posts |
All my fault. I first tried the usual DATA/READ scheme. This failed. I looked into the manual unfortunately at LOCAL and there inside ths section LOCAL DATA. It mentions RESTORE and RESTORE DATA. Many thanks again for the hints. |
Steve Drain (222) 1620 posts |
Going back to your original post, note that this syntax fills an array much more quickly than a READ/DATA loop: array()=1,2,3,4 …I would like to add that Basalt also fills arrays from DATA items. This is a bit buggy in the published version, but I have just revised it, so if you are interested … READ array() |
Thomas Milius (1471) 64 posts |
Sorry for answering so late but had only few time for my computer during the last days. Thanks for the hint with array filling. However in this particular case I think the DATA variant is not In this case I can’t use BASALT. The problem occurred during an improvement of COMCentre and therefore I am using the original BASIC to ensure as less additional installations as possible. |