Command Add '<variable>'
Symbol:
Function: This command allows you to declare a new variable in a POU and automatically update it at the point of use of the POU.
Call: Context menu Editor window > Refactoring
Requirements: The focus is on the declaration part of a POU.
The command opens the default dialog for declaring the variable. After closing the declaration dialog with OK the two-part Refactoring dialog appears.
Refactoring dialog
Left dialog part | Navigation tree of the project. Color-coding of the function blocks in which the POU is used: Red font with yellow background. After clicking on the POU object, the detailed view opens in the right part of the dialog. |
Right part of the dialog | Declaration part and implementation of the POU in whose declaration the variable is added. Color-coding of the change points: Newly added declaration in blue font and yellow background. |
Before you decide which changes you want to apply at which points, select the desired option from the drop-down list at the top right:
Add inputs with placeholder text | Default placeholder text: _REFACTOR_; editable The placeholder text defined here appears at the usage points of the newly added variables in the implementation code. It is used to find the affected locations. |
Add inputs with the following value | Initialization value for the new variable |
Commands for accepting or rejecting the change(s) are available in the context menu of the change point(s), both in the left and right part of the dialog. See also the description of the Command Rename '<variable>'.
Examples:
1. The function F_Sample is assigned a new input variable “nInput3” with initialization value “1” via refactoring. The change has the following effect:
Before:
F_Sample(nVarA + nVarB, 3, TRUE);
F_Sample(nInput1:= nVarA + nVarB, nInput2 :=3 , nInputx := TRUE);
After:
F_Sample(nVarA + nVarB, 3, TRUE, nInput3 := 1);
F_Sample(nInput1:= nVarA + nVarB, nInput2 :=3 , nInputx := TRUE, nInput3 := 1);
2. The function F_Sample is assigned a new input variable “nInput3” with placeholder text “_REFACTOR_” via refactoring:
Before:
F_Sample(nInput1 := nVarA + nVarB, nInput2 := 3, nInputx := TRUE);
F_Sample(nVarA + nVarB, 3, TRUE);
After:
F_Sample(nInput1 := nVarA + nVarB, nInput2 := 3, nInputx := TRUE, nInput3 := _REFACTOR_);
F_Sample(nVarA + nVarB, 3, TRUE, nInput3 := _REFACTOR_);
See also:
- PLC documentation: Refactoring
- PLC documentation: Auto Declare dialog