Refactoring of ST-code

A very instrumental function to quickly edit ST-code is the renaming of elements, also known as refactoring of the code.

How to refactor code within the ST-editor:

  1. Position onto an →identifier that you have already used repeatedly within ST-objects and/or PLC-objects.
    Example: In the declaration of a variable VAR var1 : INT; VAR_END go to var1.

  2. Open the context menu of the ST-editor and select Rename Element.

  3. Enter the new identifier and press the Return-key.

Observe: In case of a changed name and if this variable is already used, the corresponding code is refactored:

  • All usages of an internal or external variable in the current object are automatically renamed to the new name.

  • All usages of an input or output variable in the objects (e.g. ST-/FBD-objects) of the current project are automatically renamed to the new name.

Restriction for renaming a global or external variable

The corresponding counterpart is not automatically renamed.
This means: When renaming a global variable, the external variable of the same name is not renamed. Likewise when renaming an external variable, the global variable of the same name is not renamed.

Alternative for refactoring the element name, started from within the project explorer: See " Changing the name of an element ".