Ad Space — Top Banner

Subscript Out of Range

Amstrad Amstrad CPC

Severity: Minor

What Does This Error Mean?

Subscript Out of Range means your program accessed an array element beyond its declared dimensions. On the Amstrad CPC (Locomotive BASIC), undimensioned arrays default to 10 elements (indices 0–10).

Affected Models

  • Amstrad CPC 464
  • Amstrad CPC 664
  • Amstrad CPC 6128
  • Amstrad CPC 464+
  • Amstrad CPC 6128+

Common Causes

  • Array index exceeds the DIM size
  • Array used without a DIM — defaults to 10 but program accesses index 11+
  • Nested array dimensions wrong (2D array accessed with wrong row/column)
  • FOR loop iterating one step beyond the array boundary

How to Fix It

  1. Check your DIM statement matches how you use the array.

    DIM A(15) gives indices 0 to 15 — 16 elements total. If you access A(16), you get Subscript Out of Range.

  2. Always DIM arrays explicitly.

    Do not rely on the default 10-element arrays. Always DIM at the start of your program with the maximum size you will need.

  3. Check FOR loops that fill or read arrays.

    FOR I=0 TO 15: A(I)=I: NEXT — needs DIM A(15) or larger. Check that your loop range does not exceed the DIM.

  4. For 2D arrays, check both dimensions.

    DIM A(5,5) gives a 6×6 array (0–5 in each dimension). Accessing A(6,0) or A(0,6) gives Subscript Out of Range.

Frequently Asked Questions

Is Locomotive BASIC the same as other BASICs?

Locomotive BASIC (used on the CPC) is similar to Microsoft BASIC but has some differences. Notably, it uses 0-based arrays like Applesoft, supports structured IF/THEN/ELSE, and has built-in graphics commands tailored to the CPC's screen modes. Programs written for the Spectrum or BBC Micro often need minor changes to run on the CPC.