F_FormatArgToStr

Format helper function. This function is used internally by the FB_FormatString function block. The function can be used to convert a variable of type T_Arg into a formatted string according to the format specification.
 Return value
 Return value
| Name | Type | Description | 
|---|---|---|
| F_FormatArgToStr | UDINT | 
 | 
 Inputs
 Inputs
VAR_INPUT
   bSign      : BOOL;(* Sign prefix flag *)
   bBlank     : BOOL;(* Blank prefix flag *)
   bNull      : BOOL;(* Null prefix flag *)
   bHash      : BOOL;(* Hash prefix flag *)
   bLAlign    : BOOL;(* FALSE => Right align (default), TRUE => Left align *)
   bWidth     : BOOL;(* FALSE => no width padding, TRUE => blank or zeros padding enabled *)
   iWidth     : INT;(* Width length parameter *)
   iPrecision : INT;(* Precision length parameter *)
   eFmtType   : E_TypeFieldParam;    (* Format type field parameter *)
   arg        : T_Arg;(* Format argument *)
END_VAR| Name | Type | Description | 
|---|---|---|
| bSign | BOOL | The sign flag. | 
| bBlank | BOOL | The blank flag. | 
| bNull | BOOL | The null flag. | 
| bHash | BOOL | The hash prefix flag. | 
| bLAlign | BOOL | The alignment flag (TRUE=left align). | 
| bWidth | BOOL | If TRUE, the iWidth parameter is evaluated, otherwise not. | 
| iWidth | INT | Width parameter. | 
| iPrecision | INT | : Precision parameter. | 
| eFmtType | E_TypeFieldParam | Type parameter (type: E_TypeFieldParam). | 
| arg | T_Arg | The argument to be formatted. The following helper functions can be used to convert PLC variables of different types into the required data type T_Arg: F_BYTE, F_WORD, F_DWORD, F_LWORD, F_SINT, F_INT, F_DINT, F_LINT, F_USINT, F_UINT, F_UDINT, F_ULINT, F_STRING, F_REAL, F_LREAL. | 
 /
/ Inputs/outputs
 Inputs/outputs
VAR_IN_OUT
   sOut     : T_MaxString;
END_VAR| Name | Type | Description | 
|---|---|---|
| sOut | T_MaxString | If successful, this variable returns the formatted output string (type: T_MaxString). | 
| Return parameter | Meaning | 
|---|---|
| 0 | No error | 
| <> 0 | Error. Error description can be found at: Format error codes | 
Examples:
Formatting a BYTE variable as a binary string.
PROGRAM MAIN
VAR
    s1      : T_MaxString;
    s2      : T_MaxString;
    s3      : T_MaxString;
    s4      : T_MaxString;
    s5      : T_MaxString;
    errID   : UDINT;
    varByte : BYTE;
    double  : LREAL;
    L1      : INT;
    L2      : INT;
    L3      : INT;
    L4      : INT;
    L5      : INT;
END_VARvarByte := 128;
errID   := F_FormatArgToStr(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 20, 8, TYPEFIELD_B, F_BYTE( varByte ), s1 );
errID   := F_FormatArgToStr(FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, 20, 8, TYPEFIELD_B, F_BYTE( varByte ), s2 );
errID   := F_FormatArgToStr(FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, 20, 8, TYPEFIELD_B, F_BYTE( varByte ), s3 );
errID   := F_FormatArgToStr(FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, 20, 8, TYPEFIELD_B, F_BYTE( varByte ), s4 );
L1 := LEN( s1 );
L2 := LEN( s2 );
L3 := LEN( s3 );
L4 := LEN( s4 );The result:
s1 = '10000000'
s2 = '            10000000'
s3 = '10000000            '
s4 = '2#10000000          '
L1 = 8
L2 = 20
L3 = 20
L4 = 20
Formatting an LREAL variable.
double := 12345.6789;
errID  := F_FormatArgToStr( FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 20, 8, TYPEFIELD_F, F_LREAL( double ), s1 );
errID  := F_FormatArgToStr( FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, 20, 8, TYPEFIELD_F, F_LREAL( double ), s2 );
errID  := F_FormatArgToStr( FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, 20, 8, TYPEFIELD_F, F_LREAL( double ), s3 );
errID  := F_FormatArgToStr( FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, 20, 8, TYPEFIELD_F, F_LREAL( double ), s4 );
errID  := F_FormatArgToStr( TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, 20, 8, TYPEFIELD_F, F_LREAL( double ), s5 );
L1 := LEN( s1 );
L2 := LEN( s2 );
L3 := LEN( s3 );
L4 := LEN( s4 );
L5 := LEN( s5 );The result:
s1 = '12345.67890000'
s2 = '      12345.67890000'
s3 = '12345.67890000      '
s4 = '00000012345.67890000'
s5 = '+12345.67890000     '
L1 = 14
L2 = 20
L3 = 20
L4 = 20
L5 = 20
Requirements
| Development environment | Target platform | PLC libraries to be integrated (category group) | 
|---|---|---|
| TwinCAT v3.1.0 | PC or CX (x86, x64, Arm®) | Tc2_Utilities (System) |