Classic Computer Magazine Archive COMPUTE! ISSUE 86 / JULY 1987 / PAGE 8

Typing Proofreader Correctly

I have typed in the Commodore "Automatic Proofreader" program that appears in the back of your magazine. When I run the program, it stops at line 70 with an ILLEGAL QUANTITY ERROR message. Is this line printed correctly? I would appreciate any information that you can provide.

Stephen A. Kuhn

There are no mistakes in the Commodore "Automatic Proofreader" program or in the listing which appears in the magazine. The message you mention is due to a fairly common typing error which is tricky to interpret if you're not familiar with BASIC.

First, you need to know where to look for the error. In line 70, the computer reads a series of numbers from DATA statements elsewhere in the program and POKEs those numbers into memory. This is a common method of transferring information (in this case, a machine language program) from BASIC program lines into the computer's memory. When line 70 is executed, the computer is actually looking at the DATA values that occur in later program lines. The READ statement begins with the first DATA, value in the program and retrieves each DATA value in order. To track down the source of this error, you must carefully proofread every number in the lines that begin with DATA.

You also need to know what kind of mistake to look for. Because 255 is the largest value that a single memory location can hold, the POKE command can only store numbers in the range 0–255. The message ILLEGAL QUANTITY usually indicates that you are trying to POKE a number which falls outside that rangefor instance, a negative number, or one that's greater than 255. Thus, you should look for numbers in the DATA lines that are outside the range 0–255.

In your case, BASIC correctly indicates that the error occurred while it was performing line 70. The POKE command that triggers the error is in line 70. But the illegal quantity that POKE can't handle was pulled from a different line of the program.

Perhaps the most common cause of ILLEGAL QUANTITY errors is leaving out a comma between two DATA values. The first DATA line of the Proofreader program, for instance, begins with these two numbers:

DATA 120,169

If you forget to type the comma between 120 and 169, the READ statement interprets the number as 120169, which is much too big to be stored by POKE and triggers an ILLEGAL QUANTITY error.

The message ILLEGAL QUANTITY can also indicate that you're trying to POKE a value into some location that doesn't exist in the computer's memory. For instance, the statement POKE 65537, 12 causes an ILLEGAL QUANTITY error because, while 12 is small enough to fit in a memory address, the Commodore 64 doesn't contain a location 65537 (the highest memory address is location 65535). This sort of error might occur if you mistype lines 10–60, which detect the computer you are using and calculate addresses used by the Proofreader.

Typing mistakes also can trigger an OUT OF DATA error message. For instance, if you omit a comma between two small numbers, the wrong number that results may not be large enough to cause an ILLEGAL QUANTITY error, but the computer will run out of DATA items to read before it finishes the loop. For example, say that you omit the comma between the numbers 4 and 3 in line 160 of the Proofreader program. The computer dutifully POKEs the legal value 43, but now the program doesn't contain enough DATA items to complete the FOR-NEXT loop in line 70. Again, though the error message points to line 70, the mistake itself is found in a DATA line.

Similar errors occur if you omit a number entirely or type a period instead of a comma. If you type DATA 120.169 in line 60, for instance, the READ command in line 70 reads the fractional value 120.169 from that DATA line. However, the program doesn't stop with an ILLEGAL QUANTITY error, as you might expect. Since it's impossible to POKE a fractional value, BASIC automatically strips the fraction from the number and uses 120, which is in the legal range for POKE. The effect is the same as if you leave out a number; the program stops and warns you that it is OUT OF DATA.

Another mistake involves typing an extra comma where no comma should appear. For instance, look at line 160 of the listing in the magazine. Because that line is too long to be listed in one column, the listing breaks at the right margin; as it happens, the break occurs in the middle of the number 169. A few readers have made the mistake of inserting a comma at the break, which changes the number 169 into two numbers: 16 and 9. Since the program now contains one DATA item too many, it won't generate an OUT OF DATA message. However, to help you find typing errors, the program also calculates a checksum based on the value of each DATA item and its position in the DATA list. If you add an extra comma, the program itself detects a mistake and warns you to check your typing. The same message appears if you simply mistype a number in a way that doesn't create an illegal quantity. For instance, typing 102 instead of 120 doesn't cause an ILLEGAL QUAN­TITY error, but the program detects that you made a typing error.

Typing mistakes in DATA statements can be difficult to spot. One useful debugging technique is to get a friend to read the magazine listing aloud while you compare the listing on your screen. Another trick is to check each DATA value in reverse order, beginning with the last DATA value and working backwards to the beginning.

Other typing errors can be more difficult to spot, but just as insidious. If you scramble any of the variable names in the program, it probably won't work at all. For instance, if you type POKE AR instead of POKE ADR, or type SYS SS instead of SYS SA, don't be surprised if the computer crashes. (No real harm is done when the computer locks up; simply turn the machine off and on to regain control.) Like­wise, the Proofreader can't possibly work if you leave out a program line altogether. There's no way to check for every conceivable typing error without writing a second Proofreader program to check the first Proofreader program—which goes beyond the point of diminishing returns.

If the Proofreader stops with an error message, it's important to reload it from disk or tape for editing, rather than trying to edit the lines that remain in memory. To simplify the process of running on five different computers, the Proofreader installs its machine language in the same memory area used by the first few lines of the BASIC program (which are no longer needed by the time the computer reaches line 70). For this reason, it's important that you not delete any of the lines in the program, even if you're certain that they don't apply to your computer.