Extended instructions
9.2 String and character
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
351
VAL_STRG (convert numerical value to string)
Table 9- 26 Value-to-string operation
in:=_variant_in,
size:=_usint_in,
prec:=_usint_in,
format:=_word_in,
p:=uint_in,
out=>_string_out);
Converts an integer, unsigned integer, or floating point
value to the corresponding character string representa-
tion.
1
For LAD / FBD: Click the "???" and select the data type from the drop-down list.
Table 9- 27 Data types for the VAL_STRG instruction
IN IN
SInt, Int, DInt, USInt, UInt,
UDInt, Real, LReal
Value to convert
Number of characters to be written to the OUT string
PREC IN USInt The precision or size of the fractional portion. This does
not include the decimal point.
P IN UInt, Byte, USInt IN: Index to the first OUT string character to be replaced
This instruction converts the value represented by parameter IN to a string referenced by
parameter OUT. The parameter OUT must be a valid string before the conversion is
executed.
The converted string replaces characters in the OUT string starting at character offset count
P to the number of characters specified by parameter SIZE. The number of characters in
SIZE must fit within the OUT string length, counting from character position P. If the SIZE
parameter is zero, then the characters overwrite at position P in the OUT string without
limitation. This instruction is useful for embedding number characters into a text string. For
example, you can put the numbers "120" into the string "Pump pressure = 120 psi".
Parameter PREC specifies the precision or number of digits for the fractional part of the
string. If the parameter IN value is an integer, then PREC specifies the location of the
decimal point. For example, if the data value is 123 and PREC = 1, then the result is "12.3".
The maximum supported precision for the Real data type is 7 digits.
If parameter P is greater than the current size of the OUT string, then spaces are added, up
to position P, and the result is appended to the end of the string. The conversion ends if the
maximum OUT string length is reached.