MAX_LEN

Returns the maximum string length

This instruction returns the maximum string length set in the variable declaration from the input variable and writes the value into the output variable.

Parameters

Input

Unnamed input (STRING)

String variable declared in the POU header

Output

Unnamed output (INT)

Maximum number of characters of declaration

Remarks

  • If this instruction is used with UTF-8 strings, please refer to the notes concerning UTF-8 strings under the data type STRING.

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)

if a string applied at the input or output is an invalid string

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)

if a string applied at the input or output is an invalid string

Example

POU header

All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.

	VAR
		sTestString: STRING[128]:='A better life. A better world';
		iStringLength: INT:=0;
		iMaxStringLength: INT:=0;
	END_VAR

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 5 ;
        NETWORK_BODY
B(B_F,MAX_LEN!,,20,1,26,3,,?D?C);
B(B_VARIN,,sTestString,18,1,20,3,);
B(B_VAROUT,,iMaxStringLength,26,1,28,3,);
L(1,0,1,5);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

iMaxStringLength := MAX_LEN(sTestString);

Modified on: 2022-03-02Feedback on this pagePanasonic hotline