Attention
These docs are a bit ambitious. The steps described are accurate but IronPLC cannot yet run programs.
P4007¶
- Code
P4007
- Message
Variable not defined before used
This error occurs when a variable is referenced but not declared in the current scope.
Example¶
The following code will generate error P4007:
FUNCTION_BLOCK LOGGER
VAR
TRIG0 : BOOL;
END_VAR
TRIG := TRIG0; (* Error: TRIG is not declared *)
END_FUNCTION_BLOCK
The variable TRIG is used in the assignment but is not declared in the VAR section of the function block.
If the variable name is similar to a declared variable, the compiler will suggest
the closest match. For example, using conter when counter is declared will
produce a “did you mean” suggestion.
To fix this error, declare the variable in the appropriate variable section:
FUNCTION_BLOCK LOGGER
VAR
TRIG : BOOL; (* Declare the variable *)
TRIG0 : BOOL;
END_VAR
TRIG := TRIG0; (* Correct: TRIG is now declared *)
END_FUNCTION_BLOCK