Chapter 8 Logic Instructions
8.14.7 LEN
FB/FC
Explanation
FC
LEN calculates the number of characters in a string. DVP15MC11T
Parameters
Meaning
Description Valid range
In String Input String
Depends on the data type of the
variable that the input parameter is
Out
Number of
characters
Output
Number of
characters
Depends on the data type of the
variable that the output parameter is
Boolean
Bit string Integer
Real
number
Time, date
String
BOOL
BYTE
WORD
DWORD
LWORD
USINT
UINT
UDINT
ULINT
SINT
INT
DINT
LINT
REAL
LREAL
TIME
DATE
TOD
DT
STRING
In
●
Out
●
Note:
The symbol ● indicates that the parameter is allowed to connect to the variable or constant of the data type.
Function Explanation
The LEN instruction finds the number of characters in a string and the result is output to Out. For
example, when the string is ABCDEFGH, the value of Out is 8.
Precautions for Correct Use
The input variables are not allowed to omit. An error will occur during the compiling of the software if the
input variables are omitted. But the output variable is allowed to omit.
Programming Example
The LEN_In string is ’AaBbCcDd’. As LEN_EN is TRUE, the value of Out1 is 8.
The variable table and program
Variable name Data type Current value
Out1
UINT 8
1
LEN
EN ENO
In Out
LEN_EN
LEN_In Out1
8-199