Attribute ‘init_namespace’ΒΆ

The effect of this pragma is that a variable of the type STRING or WSTRING, which is declared in a library function block with this pragma, is initialized when used in the project with the current namespace of the library.

Syntax

{attribute 'init_namespace'}

Insertion position: the line above the line with the declaration of the variables in a library function block.

Example

The function block POU is provided with the necessary attributes:

FUNCTION_BLOCK POU
VAR_OUTPUT
 {attribute 'init_namespace'}
 myStr: STRING;
END_VAR

An instance fb of the function block POU is defined within the main program PLC_PRG:

PROGRAM PLC_PRG
VAR
 fb:POU;
 newString: STRING;
END_VAR
 newString := fb.myStr;

The variable myStr is initialized with the current namespace, for example MyLib. This value is assigned to newString in the main program.

See also