Adding a variable to a class (FB)

If the scope of the internal variables of a class (FB) is to be extended, proceed as follows. In the following example, a variable is added to the default axis type FB_Axis.

1. Create a new class (FB) and remove VAR_INPUT and VAR_OUTPUT.
FUNCTION_BLOCK FB_CustomAxis
VAR_INPUT
END_VAR
VAR_OUTPUT
END_VAR
VAR
END_VAR
2. Add the class to be inherited to the class definition using the EXTENDS keyword.
FUNCTION_BLOCK FB_CustomAxis EXTENDS FB_Axis
VAR

END_VAR
3. Create the new variables in the VAR section.
FUNCTION_BLOCK FB_CustomAxis EXTENDS FB_Axis
VAR
    bNewVariable1:        BOOL;
    nNewVariable2:        INT;
    fNewVariable3:        LREAL;
END_VAR
4. Compile the project to check the implementation for correct syntax.
You have successfully added new variables to a class.

Example result in the logged in PLC:

Adding a variable to a class (FB) 1: