Attention

IronPLC implements many parts of the IEC 61131-3 standard and is working toward full Structured Text support. Key features still missing include arrays and structures. Try it out in the IronPLC Playground.

P4031

Code

P4031

Message

Constant referenced in type parameter is not an integer type

This error occurs when a constant name is used in a type parameter (such as a STRING length or array bound) but the referenced constant is not an integer type.

Example

The following code will generate error P4031:

VAR_GLOBAL CONSTANT
    MY_CONST : REAL := 3.14;
END_VAR

FUNCTION_BLOCK MyFB
VAR_INPUT
    name : STRING[MY_CONST];
END_VAR
END_FUNCTION_BLOCK

The constant MY_CONST is a REAL type, which cannot be used as a string length. To fix this error, use an integer type:

VAR_GLOBAL CONSTANT
    MY_CONST : INT := 100;
END_VAR