
RE-DIMENSIONALIZING VARIABLES
Good morning, Class! Happy Valentine’s day to you all.
Today’s session will be on re-dimensionalizing variables. Have you ever had a program where you were entering data, such as names and addresses or inventory items and ran out of dimension space because the program was designed to hold only a certain amount of items?
Let’s take a hypothetical situation. Let’s say that the program in question is designed to hold 100 inventory items and related data in a 16K machine. You have filled the program with enough data to bulk out this amount.
Now, let us say that you have purchased a 64K RAMpack and want to increase the total to accomodate 300 items – but, YOU DON’T WANT TO HAVE TO RE-ENTER THE ORIGINAL 100 ITEMS.
You probably know that if you edit the program line(s) with the DIM statements from values of 100 to 300, all the data will be lost when you execute those lines, even when you use the GOTO command. You may have encountered this problem and typed in the data all over again.
There is a relatively simple method where with a few program lines added to the program and by executing a few GOTO commands, you can save yourself hours of data re-entry. Here is how it works!
All that has to be done is to transfer the existing data into other variables that have been dimensionalized for the same amount, in our example this is 100. Let us say we had 100 inventory items with 100 amounts in our program. Of course, there would be other fields such as cost, description, etc., but we’ll work with two data entries per item to give you an idea how multiple fields can be redimensionalized.
SWITCHING DATA
Let us say that in our original program, the first two lines are as follows:
10 DIM A$(100,10)
20 DIM A(100)
where “A$” represents the string variable array to be used to hold the item description or part number and “A” is the numeric variable array that will hold the “amount of each item in stock” data. If there are more DIM statements, keep these in mind for the following rooutines.
Let us say that our program menu starts at line 100 and that the lines from 9000 on up are not used in the program(if you choose to use another line portion of the program, make sure a STOP statement is entered between the routines we are about to enter and the next existing line). We would now type in the following lines:
9000 DIM B$(300,10)
9010 DIM B(300)
Assuming, of course that “B$” & “b” are not being used or at this time are not in any other part of the program (Use lines 9011 to 9019 for any other variables that are in the existing program). If they are, choose different letters. Enter the folowing lines:
9020 FOR N=1 TO 100
9030 LET B$(N) = A$(N)
9040 LET B(N) = A(N)
(9041 to 9049 for any other variables to be transferred)
9050 NEXT N
We have now transferred the data into new variables that are dimensionalized to the larger number “300”. Now enter:
9060 DIM A$(300,10)
9070 DIM A(300)
(9071 to 9079 for any other variables to be dimensionalized)
9100 FOR N=1 TO 300
9110 LET A$(N) = B$(N)
9120 LET A(N) = B(N)
(9121 to 9129 for any other variables to be transferred)
9130 NEXTN
Now enter “GOTO 9060”
The transfer is complete – but we are not finished! We have the problem of a lot of memory space still being used up. Change the “100”s in lines 10 & 20 to “300” and enter “DIM B$(1,1) and “DIM B(1)” (use this format for any other variables to be removed). This has the effect of allowing the program to accept 300 entries and clearing that portion of the program’s memory to allow near maximum space available to be used.
Now delete all the 9000 lines. Find any FOR/NEXT loop routines that cycle to 100 and change the “100” to “300”.
Finally enter “GOTO 100” or whatever the menu return line is.
The program should now have the original 100 data items with (related fields) intact and allow entry of 200 more. Class dismissed!
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.