Have you ever typed a long list of information into an array, and then attempted to RUN your program, only to find out that the RUN command wiped out the entire array? The first thing you say to yourself (after cursing at the computer) is “why didn’t I put the data in a Data Statement?”
DATA Statements have some other advatages over arrays. When storing strings, all the strings in an array must be as long as the longest string (shorter strings are followed by spaces). Therefore, if you’re trying to conserve bytes, a data statement may be the answer. You can also save RAM bytes by storing numbers as strings, and then using the VAL function when you need the numbers for mathematical calculations.
Now, why don’t we use DATA Statements more often? The answer is simple: it takes forever to type in all those quotation marks, commas, and line numbers. To eliminate this problem, I wrote a program that allows you to type in your data, depressing only the ENTER key between each item in your list. To use this program, we must first reserve room in RAM for the DATA Statement. To do this, first MERGE any other program which has more bytes of BASIC than your longest DATA Statement will have. If you do not have a program which is long enough, you can MERGE several programs. Do not be concerned that the MERGEd programs do not make sense. They are only used to occupy space in RAM. It’s better to MERGE a program(s) that is much longer than necessary, otherwise, a long DATA Statement might overflow the reserved bytes of RAM. 20,000 bytes is probably sufficient for your longest DATA Statement, and does not take too long to MERGE.
Now, MERGE “DATAGEN“, and then enter the following command: GOTO 9999. This will SAVE all the merged programs, including “DATAGEN”. Now, you can either LOAD “DATAGEN”, or RUN 9976. The following should be printed before the program listing. CAUTION: RUNing this program will delete some (or all) of the program, so SAVE it immediately after typing it into your computer. The command GOTO 9999 will save it.
MORE PROGRAM NOTES: Be aware that if you input a high number (say 20000) as the desired DATA Statement length, then if you do not enter 20000 bytes of data, there will be a delay as the program pokes in spaces from the last entered piece of data to the end of the line. Example: You ask for 20000 bytes in the DATA Statement, and only enter 1000 bytes…then it may take about 10 minutes to POKE 19000 spaces into the data line. This problem will not occur in normal use of the program.
9972 REM MERGE a program(s) with more bytes of BASIC than your longest DATA STATEMENT.
9973 REM MERGE "DATAGEN"
9974 REM GOTO 9999 to SAVE the above merged programs.
9975 REM Now you can either LOAD "DATAGEN" or RUN 9976
9976 CLS : POKE 23561,200: POKE 23609,100: INPUT "How many bytes do you want in the DATA statement? ";n
9977 INPUT "What will be [illegible] line number of the DATA statement?"'"(the line number must be less than 9997)";l: IF NOT (l<9997) THEN GO TO 9977
9978 PRINT INVERSE 1;AT 10,10;"PLEASE WAITE": LET prog=PEEK 23635+256*PEEK 23636
9979 LET adr=prog-1
9980 LET adr=adr+4+PEEK (adr+3)+256*PEEK (adr+4)
9981 IF prog+5+n<adr THEN LET ad=adr: GO TO 9983
9982 GO TO 9980
9983 POKE prog,0: POKE prog+1,1
9984 LET bytes=ad-prog-3: POKE prog+3,INT (bytes/256): POKE prog+2,bytes-256*INT (bytes/256)
9985 POKE prog+4,228
9986 CLS : PRINT "Enter data. Depress the ENTER key after each entry."''"Enter the word ""end"" to end the list"''"Number of bytes in"'"DATA list; ";bytes-3;'"(this includes quotes, commas,"'"and the word ""DATA"")."
9987 LET adr=prog+4
9988 LET adr=adr+1: POKE adr,34
9989 BEEP .02,1: BEEP .02,1: INPUT d$: IF d$="end" OR d$="END" THEN CLS : GO TO 9994
9990 IF adr+LEN d$+4>ad THEN CLS : PRINT AT 5,0;"""";d$;"""";" does not fit in this"'"data list. Start another"'"data list.": GO TO 9994
9991 FOR z=1 TO LEN d$: LET adr=adr+1: POKE adr,CODE d$(z): NEXT z
9992 LET adr=adr+1: POKE adr,34: LET adr=adr+1: POKE adr,44
9993 GO TO 9988
9994 PRINT AT 10,10;"PLEASE WAITE": FOR z=adr-1 TO ad-1: POKE z,32: NEXT z
9995 BEEP 1,5: BEEP 1,-5: BEEP 1,5: BEEP 1,-5: PRINT AT 15,0;"Depress letter D to DELETE this program. The DATA LIST will notbe deleted."
9996 IF INKEY$<>"d" AND INKEY$<>"D" THEN GO TO 9996
9997 DELETE 2,9996: POKE prog,INT (l/256): POKE prog+1,l-256*INT (l/256): CLS
9998 DELETE 9997,
9999 SAVE "DATAGEN" LINE 9976
Media
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.