Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

E008: Invalid Range

This error is emitted when an array range declaration is malformed. There are two cases that trigger it.

1. Missing or malformed range

An array dimension must be written as start .. end. A bare literal or any other expression in a dimension slot is rejected, including in multi-dimensional arrays where any single dimension is not a range.

Invalid:

VAR
    arr1 : ARRAY[5] OF DINT;           // bare literal, no range
    arr2 : ARRAY[0..5, 5] OF DINT;     // second dimension is not a range
END_VAR

How to fix

Use start .. end for every dimension:

VAR
    arr1 : ARRAY[0..5] OF DINT;
    arr2 : ARRAY[0..5, 0..5] OF DINT;
END_VAR

2. Non-integer range bounds

Array range bounds must be of an integer type. BOOL, REAL / LREAL, STRING / WSTRING, time/date types, and other non-integer types are rejected. This matches the IEC 61131-3 requirement that array dimensions are integer-indexable.

Invalid:

VAR
    a : ARRAY[FALSE .. TRUE] OF BOOL;       // BOOL bounds
    b : ARRAY[1.5 .. 3.5] OF INT;           // REAL bounds
    c : ARRAY['a' .. 'z'] OF INT;           // STRING bounds
    d : ARRAY[T#0s .. T#1s] OF INT;         // TIME bounds
END_VAR

How to fix

Use integer literals, integer constants, or integer-typed expressions:

VAR_GLOBAL CONSTANT
    LO : DINT := 0;
    HI : DINT := 10;
END_VAR

VAR
    a : ARRAY[0..1] OF BOOL;
    b : ARRAY[LO..HI] OF INT;
END_VAR

Valid integer types

The valid integer types for array bounds are the same as for enum base types (see E122): SINT, USINT, INT, UINT, DINT, UDINT, LINT, ULINT, BYTE, WORD, DWORD, LWORD.