Command ‘Refactoring’ - ‘Add variable’

Symbol:

Function: This command enables the declaration of variables in a POU, as well as the automatic update to the occurrence of the POU.

Call: Main menu Edit ‣ Refactoring , or right-click.

Requirements: The declaration part is in focus.

The command opens the default dialog box for declaring variables.

See also

Dialog box ‘Refactoring’

After clicking OK to close the declaration dialog, the Refactoring dialog box opens with two frames.

Right Dialog Frame

Declaration part and implementation of the POU where the variable is added.

Colored highlighting of changed locations: New added declarations have a blue font and are highlighted in yellow (1).

Left Dialog Frame

Device tree or POUs tree of the project.

Colored highlighting of blocks where the POU is used: red font and yellow highlight (2).

After you double-click the POU object, the detail view opens.

Before you decide which changes to accept at which locations, select the required option from the drop-down list (3) at the upper right part of the window:

Add inputs with placeholder text

Default placeholder text: _REFACTOR_; editable

The placeholder text defined here is used at the occurrence locations of the new added variables in the implementation code. This is used for searching for the affected locations.

Add inputs with the following value Initialization value for the new variable.

You can accept or reject changes by right-clicking the changed locations or by executing commands in the left or right area of the dialog box. Refer to the description of the Refactoring ‣ Rename command.

Examples

  1. By refactoring, the fun block receives a new input variable input3 with the initialization value 1. The change has the following effect:

Before:

fun(a + b, 3, TRUE);
fun(input1:= a + b , input2 :=3 , inputx := TRUE);

After:

fun(a + b, 3, 1, TRUE);
fun(input1:= a + b , input2 :=3 , _REFACTOR_, inputx := TRUE);
  1. By refactoring, the “fun” block receives a new input variable input3 with the placeholder text “_REFACTOR_”:

Before:

inst(input1 := a + b, input2 := 3, inputx := TRUE);
fun(a + b, 3, TRUE);

After:

inst(input1 := a + b, input2 := 3, input3 := _REFACTOR_, inputx
:= TRUE);
fun(a + b, 3, _REFACTOR_, TRUE);

See also