Classic Computer Magazine Archive ANTIC VOL. 3, NO. 2 / JUNE 1984

The Toolbox

BASIC - A Variable Approach
A variable-list utililty everyone needs

by Jerry White

Synopsis

This article presents a variable-list utility that aids in the debugging of BASIC programs. The article's two programs require a disk drive, a printer and a minimum of 16K RAM, and run on all Atari computers.

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.

Typing and Storing the Programs

First, type in Listing I and leave out the REM statements. (To keep it short, I didn't include any error trapping in this program.) LIST it to disk with the following command:

LIST "D:VARIFILE.LST"

Next, type in Listing 2, and SAVE it with this command:

SAVE "D:VARISORT"

How to Use the Programs

First, LOAD your own BASIC program. My variable-lister program coexists with your program in RAM, so make sure that your program does not use lines 32000 to 32020. In addition, it should not use the following variable names: JP$, JFS, JD$, JR, and JC. Also, use no more than 123 variables.

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.

Using Longer Names

If you want to use longer names and descriptions, it's easy to make the maximum entry length exceed 39 characters. For instance, if you want to use 80 characters, make the following changes in both programs. Change all incidences of 39 to 80, and all incidences of 38 to 79 (the field length minus one).

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
TURN
Listing 1: VARISORT.BAS Download

Listing 2: VARIFILE.LST Download / View