?ILLEGAL QUANTITY ERROR
Commodore Commodore 64
Severity: MinorWhat Does This Error Mean?
?ILLEGAL QUANTITY ERROR means you passed a number to a BASIC function or command that is outside the allowed range. The most common causes are SQR of a negative number, a negative POKE address, or a value outside 0-255 in a POKE statement.
Affected Models
- Commodore 64
- Commodore 64C
- Commodore 128 (C64 mode)
- VICE emulator (C64)
Common Causes
- SQR() called with a negative number (square root of negative is not defined)
- LOG() called with zero or a negative number
- POKE or PEEK with an address outside the valid range (0-65535)
- A value outside 0-255 used in a POKE byte value
- CHR$() called with a value outside 0-255
- Array subscript less than zero
How to Fix It
-
Check the line number shown next to the error and LIST that line.
BASIC tells you which line triggered the error. Type LIST 100 (replacing 100 with your line number) to see just that line.
-
If using SQR(), make sure the number inside is positive.
SQR(-4) is illegal. Add an ABS() wrapper if needed: SQR(ABS(X)) will always give a valid result.
-
If using POKE, check both the address and the value.
POKE address, value — the address must be 0 to 65535, and the value must be 0 to 255. POKE 53280, 256 will give ILLEGAL QUANTITY because 256 is one too high.
-
If using CHR$(), the value must be between 0 and 255.
CHR$(300) is illegal. C64 BASIC only supports the PETSCII character set which uses values 0-255.
-
Add a check before the problematic line to validate the value.
For example, before SQR(X), add: IF X < 0 THEN X = 0 This prevents the error by guarding against illegal values at runtime.
Frequently Asked Questions
Why is 256 an illegal quantity for POKE?
The C64's memory is byte-addressed. A byte can only hold values from 0 to 255 (8 bits). 256 requires 9 bits and does not fit, so BASIC rejects it.
Does this error appear in VICE emulator too?
Yes. VICE accurately emulates Commodore BASIC V2 including all error messages. If your code triggers ILLEGAL QUANTITY in VICE, it would have done the same on real hardware.