After the premier issue of T-S Horizons was published, I received a letter regarding my article “Creating and Saving Files.” (TSH#1, p. 20). I mentioned in that article that it was important to set the array size large enough to hold all foreseeable files that you would want to store there, because redimensioning the array to a larger size would wipe out all your existing information. But the writer of this letter notes that in cases where enough memory is available, it is possible to expand an array by temporarily storing it in a second array. Below are excerpts from his letter.
Let’s say, for instance, that your existing string array is DIM A$ (30,3). If you later require a larger array (A$(40,4) for example) you can DIM B$(40,4) followed by:
10 FOR N=1 TO 30
20 LET B$(N,TO 3)=A$(N)
30 NEXT N
If plenty of memory is available, re-DIMension A$(40,4) to wipe out the original A$ array (after moving it to the B$ array) and run another FOR-NEXT loop to move everything back to the new A$ array.
The alternative is to change the name of the array from B$ to A$ by poking the first byte of the array. Refer to page 131, Chapter 26, TIMEX USER MANUAL for the TS1000. An array of characters will be identified in storage by a Letter from 198 to 223 Decimal (C6 to DF Hex). Subtract 20 Hex or 32 Dec and you will find a character Code from 166 for Inverse A to 191 for Inverse Z. In this case we would want to change the Code from 199 to 198.
There are two ways to find the location of the byte we want to change. Whenever I want to make it easy on myself to locate arrays in memory, I make sure that the appropriate DIMs appear in the program before any other DIMs, LETs or INPUTs (assignments). In this way, the System Variable VARS at 16400+256*16401 will always tell me where the first byte of the first assignment is. Now, the first element will be offset from that first byte depending upon the type of variable; but right now I am only interested in changing the name of this array, which will be that first byte. So, I’ll have to tell you that in this case the byte we are looking for will not be pointed to by VARS, but by another system variable, DEST at 16402+256*16403. The plot thickens. We have to do the following: Assuming that B$(1,TO3)=”OHI” …..PRINT PEEK 16402+256*PEEK16403 AFTER this: LET B$(1,1)=”O”……….FROM the address resulting subtract (in this case) eight. Then PEEK this last result (in this case, it should be 199). 199 minus 32=167 which is Inverse B. POKE that byte with 198. Then, try PRINT A$(1) and it should print “OHI”.
Incidentally, when I use BASIC to delete an array or string which I no longer need, I use e.g., DIM K$(1). If I use DIM K$(0) I get an Error Code 3; and I do not want to bother my user with Error Codes. Machine Code can do a cleaner job; but, CLEAR is generally unusable; so the DIM(1)s are a good compromise.
John A. Lyons
Columbus, Oh
Obviously this method will not work if there is not enough RAM for the two expanded arrays. (In my file program, the main storage array T$(700,36) uses over 25K of memory.) But if you have enough RAM, this can be a valuable tip no matter what computer you are programming on.
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.