The following article was printed in March 1988 of the magazine „8000 PLUS".
(Followed by a correction in April 1988)
A BASIC program creating references in BASIC programs1
Variable Lister
by Geoff Buckeridge
 
Now all you BASIC programmers have no excuse for not being really organised. Of course it's a good idea to take a careful note of all those variables in a program and what they all do but somehow life always seems loo short to do it. Now this program does virtually everything for you. It simply goes through any listing you want, extracts the names of all the variables, and then presents them in a couple of helpful layouts.
It is really invaluable for those times when you have to stop halfway through a program or when you have a program that you want to develop further. Just save your program in ASCII form (type save "filename",a) and then run this listing. Enter the name of the program to be worked on when asked, and it immediately sets to work picking out all the variables it can find and printing them on screen.
It then allows you to either view on screen or print out the information in a couple of different forms. Style one sorts the variables into alphabetical order, lists the number of times the variable is used and the line numbers it is used in.
Style two lists each variable with the number of the lirst line it is used in, the number of times it is used and a space to allow you to write in a brief description of what the variable does.
One point of interest is the POKE in line 330 which takes everything that would normally be shown on screen and prints out a hard copy. Line 520 puts everything back in order.
[BASIC-Listing]

Gremlins Corner

This month's Gremlins Corner doesn't deal so much with mistakes as with one or two suggested improvements to last month's listings.
The Variable Lister has posed a few problems because the programs you have been running through it are so complicated. If you have more than 50 different variables in your program, the Lister will go wrong. This is easily fixed by changing the DIM statement in line 10. Bump the 50s in this line up to a figure greater than your greatest number of variables to solve this (for example DIM var$(150)).
More complicated is the fact that some programs put through the lister are producing a 'String too long' error message. This is because you've got too many occurrences of a variable (like over 50), and the variable ln$ is getting more than 255 characters in it. Here is a suggestion from Mr J Dulton to get round this. Change line 390 to:
390 a$=ln$(i%):newa$=newln$(i%)
and then change 410 to
410 IF b%=0 THEN newa$=aS+newa$:GOTO 441
Then add
441 IF newa$="" THEN 450 ELSE a%=LEN(newa$):b%=INT(a%/55)
442 IF b%=0 THEN PRINT TAB(26) newa$:GOTO 450
443 c%=INSTR(50,newa$,","):IF c%=0 THEN c%=a%+1
444 PRINT TAB(26) LEFT$(newa$,c%-1):newa$=RIGHT$(newa$,a%-c%)
445 GOTO 441
Now alter 540 to
540 IF var$<>var$(j%) THEN 550
and add
542 no%(j%)=no%(j%)+1
546 IF LEN(ln$(j%))>240 THEN newln$(j%)=newln$(j%)+","+line$ ELSE ln$(j%)=ln$(j%)+","+line$
Other matters to clear up are the fact that of course the program only differentiates between variables and BASIC command words by the fact that it expects variables in lower case and commands in upper case. If you have a program with variables in capitals you must convert them to lower case, which is easily done with PIP. The command
PIP FREDL.BAS=FRED.BAS[L]
creates a file FREDL.BAS which is a lower case version of FRED.BAS (you must have saved FRED.BAS with the ,A option in BASIC). You then convert the BASIC keywords back into upper case simply by LOADing and reSAVEing the program - BASIC automatically converts all the command words back into capitals, so the Variable Lister only picks up the variables.
The final point is something we omitted to mention. The Lister expects the first line of your program to be a REM line which it prints at the top of the page to help you keep track of which program is being listed. If you have any variables in this line they will be ignored.
[The adapted BASIC listing]

1. The POKE instructions used by the program restricts the usage of this tool. The address 18527 (&H485F) refers to Mallard BASIC version 1.29. I found the appropriate address for version 1.47 used by me, but the tool doesn't run with Microsoft BASIC.

The address refers to the statement table starting at &H47F9 for version 1.29 and &H4976 for version 1.47. Address &H485F holds the word &H5E64, the address of the PRINT statement. The POKE instruction changes it to amp;H5E5A, the address of the LPRINT statement.
330 IF a$="Y" THEN POKE 18527,90 ELSE POKE 18527,100
520 POKE 18527,100:END

At version 1.47 this is &H6047 for PRINT and &H603d for LPRINT. In this case POKE at address &H49DC:
330 IF a$="Y" THEN POKE 18908,61 ELSE POKE 18908,71
520 POKE 18908,71:END
A solution for this problem may be to select POKE dependent on the version — similar to FIREWORX — or select LPRINT instead of PRINT if the result should be logged.
In the early days I wrote an assembler programm to list variables in BASIC. This program only runs with Mallard BASIC, too — in addition to it the program uses the tokenized BASIC program instead of ASCII. A better choice is the program for BASIC references which I adapted for the PCW.

HTML customization by Werner Cirsovius
December 2014
© 8000 PLUS