ANTIC VOL. 3, NO. 2 / JUNE 1984 / PAGE 58
If you program in BASIC, you're probably aware of the importance of keeping track of variables in a program. You can use the two short programs presented here to create a variable-definition chart. This chart provides a list of all of your program's variables in alphabetical order, along with a short definition of each variable. This makes your program much easier to understand.
LIST "D:VARIFILE.LST"
Next, type in Listing 2, and SAVE it with this command:
SAVE "D:VARISORT"
ENTER the utility with this command:
ENTER "D:VARIFILE.LST"
To use the utility, type:
GOTO 32000
Variable names are displayed on the screen one at a time. String names are followed with '$' and array names are followed with'('. As each name appears, type in a brief description, then press [RETURN]. To make the chart easier to read, type at least one space at the beginning of your entry If you use the [TAB] key, the definition field will automatically be left-justified, but this will leave less room for the description. The total entry, including variable name, description, and spaces, cannot exceed 39 characters.
When all variables have been defined, the utility closes the data file (D:VARI ABLE.DAT) and runs the VARISORT program. VARISORT reads the data file into a string and sorts it by variable name into alphabetical order. You're then asked to type in a heading for the printed listing. Your heading should include the program name and revision number, as well as the date.
The number 4797, which appears twice in line 100 of the VARISORT program (Listing 2), was derived by multiplying the field length (39) by the maximum number of records (123). If you increase the field length to 80, you have to change 4797 to 9840 (80*123) in both places.
Jerry White is an institution in the world of Atari computing, and a long-time Antic Contributing Editor.
Listing 1 0 REM VARIFILE.LST I REM BY JERRY WHITE 2 REM ANTIC MAGAZINE 32000 GRAPHICS 0:POKE 82,0:POKE 710,0: ? ,"DEFINE VARIABLES:":? :DIM JF$(39), JP$(39),JD$(39) 32002 JP$=" ":JP$(39)=" ":JP$(2)=JP$:J F$="":CLOSE #1:OPEN #1,8,0,"D:VARIABLE .DAT" 32004 FOR JC=PEEK(131)*256+PEEK(130) T 0 PEEK(133)*256+PEEK(132)-l 32006 IF PEEK(JC)<128 THEN JR=JR+1:JF$ (JR,JR)=CHR$(PEEK(JC)):GOTO 32020 32008 IF PEEK(JC)>=128 THEN JR=JR+1:JF $(JR,JR)=CHR$(PEEK(JC)-128) 32010 TRAP 32012:IF JF$="JR" OR JF$="J P$" OR JF$="JC" OR JF$="JF$" OR JF$="J D$" THEN 32018 32012 TRAP 40000:? JF$;:INPUT JD$:JR=J R+LEN(JD$):JF$(LEN(JF$)+1)=JD$:IF JR>= 39 THEN 32016 32014 JF$(JR+1,39)=JP$(JR+1,39) 32016 ? #1;JF$ 32018 JR=O:JF$="":JD$="" 32020 NEXT JC:CLOSE #1:RUN "D:VARISORT" Listing 2 0 REM VARISORT 1 REM BY JERRY WHITE 2 REM ANTIC MAGAZINE 100 DIM A$(4797),B$(39),C$(39):A$=" ": A$(4797)=" ":A$(2)=A$:B$="":C$="":GOTO 210 110 T=INT(T/3)+1:FOR Ll=l TO REC-T:FOR L2=Ll TO 1 STEP -T 120 IF A$(L2*39-38,L2*39)<=A$((L2+T)*3 9-38,(L2+T)*39) THEN 160 130 C$=A$(L2*39-38,L2*39):A$(L2*39-38, L2*39)=A$((L2+T)*39-38,(L2+T)*39) 140 A$((L2+T)*39-38,(L2+T)*39)=C$ 150 NEXT L2 160 POKE 709,L1*2:NEXT L1 170 IF T>l THEN POKE 53279,0:GOTO 110 180 POKE 709,10:GOSUB 270:? :? "TYPE H EADING FOR PRINTED LIST:":INPUT B$ 190 TRAP 240:LPRINT B$:LPRINT :TRAP 40 000:GOSUB 270 200 FOR ME=l TO REC:LPRINT A$(ME*39-38 ,ME*39):NEXT ME:LPRINT :LPRINT REC;" V ARIABLES":POKE 82,2 201 ? :? "BASIC":? "IS";:END 210 REC=0:OPEN #1,4,0,"D:VARIABLE.DAT" :GRAPHICS 18:POSITION 7,4:? #6;"READIN G" 220 TRAP 230:INPUT #1,B$:REC=REC+1:POS ITION 9,6:? #6;REC:A$(REC*39-38,REC*39 )=B$:B$="":GOTO 220 230 T=REC:GRAPHICS 18:POSITION 7,4:? # 6;"sorting":GOTO 110 240 ? CHR$(253):? " CHECK PRINTER, PRE SS START WHEN READY"; 250 IF PEEK(53279)<>6 THEN 250 260 GOTO 190 270 GRAPHICS 0:POKE 710,0:POKE 82,0:RE TURNListing 1: VARISORT.BAS Download