Placeholders with Format Definition in the Output Text

A character string which is output in the visualization can include the placeholder % for a variable. At runtime, the placeholder is replaced by the actual value of the variable in the defined format. The data type in the format definition and of the variable have to be identical. A character string can contain a maximum of one placeholder.

Character strings for output are listed in the Text property. The assigned variable is listed in the Text variable property.

See also

For the output of integers

%d

%i

Output of variable (integer data type) as decimal number

Code: iCounter : INT := 12;

Property Text: Value: %i

Property Text variable: PLC_PRG.iCounter

Output: Value: 12

%b

Output of variable (integer data type) as binary number

Code: byCode : BYTE := 255;

Property Text: Coding: %b

Property Text variable: PLC_PRG.byCode

Output: Coding: 11111111

%o

Output of variable (integer data type) as unsigned octal number without a preceding zero

Code: byCode : BYTE := 8#377;

Property Text: Coding: %o

Property Text variable: PLC_PRG.byCode

Output: Coding: 377

%x

Output of variable (integer data type with max. 32 bits) as unsigned hexadecimal number without a preceding “0x”

Code: dwCode : INT := 16#FFFFFFFF;

Property Text: Coding: %x

Property Text variable: PLC_PRG.dwCode

Output: Coding: ffffffff

%llX

%012llX

Output of 64-bit variable (LWORD, LINT, ULINT) as hexadecimal number.

Note: llx means “long long hexadecimal”

Code: lwCode : LWORD := 16#4FFF_3FFF_2FFF_1FFF;

Property Text: Coding: %llx

Property Text variable: PLC_PRG.lwCode

Output: Coding: 4fff3fff2fff1fff

%u

Output of variable (integer data type) as unsigned decimal number

Code: uiNumber : UINT := 1234;

Property Text: Number: %u

Property Text variable: PLC_PRG.uiNumber

Output: Number: 1234

For the output of floating-point numbers

Floating-point numbers have the data type REAL or LREAL.

%f

In decimal form with decimal point in format 1.6

Code: rWeight : REAL := 1.123456789;

Property Text: Weight: %f

Property Text variable: PLC_PRG.rWeight

Output: Weight: 1.123456

%<alignment><minimum width>.<accuracy>f

As decimal number in user-defined format

  • <alignment>: - or +, optional

    -: Left-aligned

    +: Right-aligned

  • <minimum width>: Number of places to the left of the decimal point

  • <accuracy>: Number of places to the right of the decimal point

Code: rWeight : REAL := 12.1

Property Text: Weight: %2.3f

Property Text variable: PLC_PRG.rWeight

Output: Weight: 12.100

%e

Output of floating-point number (REAL or LREAL) in exponential notation of base 10

Code: rValue : REAL := 1.234567%e-003;

Property Text: Value: %E

Property Text variable: PLC_PRG.rValue

Output: Value: 1.23E-6

%E

Code: rValue : REAL := 1.234567%e-003;

Property Text: Value: %e

Property Text variable: PLC_PRG.rValue

Output: Value: 1.23e-6

For the output of text

%c

Output of single character in ASCII character set

Code: bChar := 16#41;

Property Text: Key: %c

Property Text variable: PLC_PRG.bChar

Output: Key: A

%s

Output of character string

Code: strName := 'Paul Smith';

Property Text: Name: %s

Property Text variable: PLC_PRG.strName

Output: Name: Paul Smith

For the output of the percent sign

%%

Output of percent sign in character string

Property Text: Valid until 90%%

Output: Valid until 90%

Code: iPercentage : INT := 80;

Property Text: Valid until %d%%.

Property Text variable: PLC_PRG.iPercentage := 80;

Output: Valid until 80%

For the output of the date and time

If the output text in the element Text property contains the placeholder “%t”, then a date and/or time is output. If a variable is not specified in the Text variable property, then the system time is output; otherwise it is the value of the variable.

By default, the names of the days and months are displayed in English. If localized texts are used, then the text list System has to be supplemented. This text list is created automatically in the POUs view when the placeholder %t is used. The English terms have to be used as the ID here. The localization can be done for both the abbreviated names and full names.

Time data types include LTIME, TIME, TIME_OF_DAY, TOD, DATE, DATE_AND_TIME, and DT.

Note

Compatibility Notice In order to get the usual display, in V3.5 SP17 and higher, as a rule three digits are used for the output of fractions of a second (ms/µs/ns). Example: In %t[dd-HH:mm:ss:ms], ms is specified with three digits for the milliseconds. For this purpose, the two-digit ms number is prepended with a zero. If a two-digit output is desired (like before V3.5 SP17), then a special compiler define has to be set in the compiler properties of the application: VISU_MILLISEC_NOLEADING_ZERO.

Date and time formats

%t[yyyy]

Year with century

Code: dateBy : DATE := DATE#2020-1-1;

Property Text: By the year %t[yyyy]

Property Text variable: PLC_PRG.dateBy

Output: By the year 2020

%t[yy]

Year without century (00–99)

Code: dateSince : DATE := DATE#2000-1-1;

Property Text: Since: %t[yy]

Property Text variable: PLC_PRG.dateSince

Output: Since: 00

%t[y]

Year without century (0–99)

Code: dateSince : DATE := DATE#2000-1-1;

Property Text: Since: %t[y]

Property Text variable: PLC_PRG.dateSince

Output: Since: 0

%t[MMMM]

Month as full name

Code: dateMonth : DATE := DATE#2016-1-1;

Property Text: Month: %t[MMMM]

Property Text variable: PLC_PRG.dateMonth

Output: Month: January

%t[MMM]

Month as abbreviated name

Code: dateMonth : DATE := DATE#2016-1-1;

Property Text:: Month: %t[MMM]

Property Text variable: PLC_PRG.dateMonth

Output: Month: Jan

%t[MM]

Month as number (01–12)

Code: dateMonth : DATE := DATE#2016-1-1;

Property Text:: Month: %t[MM]

Property Text variable: PLC_PRG.dateMonth

Output: Month: 01

%t[M]

Month as number (1–12)

Code: dateMonth : DATE := DATE#2016-1-1;

Property Text:: Month: %t[M]

Property Text variable: PLC_PRG.dateMonth

Output: Month: 1

%t[ddddd]

Day of week as number (1=Monday – 7=Sunday)

Code: iDay : INT := 7;

Property Text:: Day: %t[ddddd]

Property Text variable: PLC_PRG.iDay

Output: Day: 7

%t[dddd]

Day of week as full name

Code: iDay : INT := 7;

Property Text:: Day: %t[dddd]

Property Text variable: PLC_PRG.iDay

Output: Day: Sunday

%t[ddd]

Day of week as abbreviated name

Code: iDay : INT := 7;

Property Text:: Day: %t[ddd]

Property Text variable: PLC_PRG.iDay

Output: Day: Sun

%t[dd]

Day of month as number (01–31)

Code: iDay : INT := 1;

Property Text:: Day: %t[dd]

Property Text variable: PLC_PRG.iDay

Output: Day: 01

%t[d]

Day of month as number (1–31)

Code: iDay : INT := 1;

Property Text:: Day: %t[d]

Property Text variable: PLC_PRG.iDay

Output: Day: 1

%t[jjj]

Day of year as number (001–366)

Code: dateOfNoReturn : DATE := DATE#2016-09-01;

Property Text:: Day of no return: %t[jjj]

Property Text variable: PLC_PRG.dateOfNoReturn

Output: Day of no return: 245

%t[HH]

Hour in 24-hour format (00–23)

Code: todEnd : TOD := TIME_OF_DAY#17:0:0;

Property Text: Ends at: %t[HH]:00

Property Text variable: PLC_PRG.todEnd

Output: Ends at 17:00

%t[hh]

Hour in 12-hour format (01–12)

Code: todEnd : TOD := TIME_OF_DAY#17:0:0;

Property Text: Ends at: %t[hh] o'clock

Property Text variable: PLC_PRG.todEnd

Output: Ends at: 05 o'clock

%t[mm]

Minutes with leading zero (00–59)

Code: tPeriod : TIME := T#5M;

Property Text: Period: %t[mm]m

Property Text variable: PLC_PRG.tPeriod

Output: Period: 05m

%t[m]

Minutes without leading zero (0–59)

Code: tPeriod : TIME := T#5m;

Property Text: Period: %t[m 'm']

Property Text variable: PLC_PRG.tPeriod

Output: Period: 5 m

%t[ss]

Seconds with leading zero (00–59)

Code: tPeriod : TIME := T#5m3s;

Property Text: Period: %t[mm'm'ss's']

Property Text variable: PLC_PRG.tPeriod

Output: Period: 05m03s

%t[s]

Seconds without leading zero (0–59)

Code: tPeriod : TIME := T#5m3s;

Property Text: Period: %t[m'm' s's']

Property Text variable: PLC_PRG.tPeriod

Output: Period: 5m 3s

%t[ms]

Milliseconds without leading zero (0–999)

Code: tPeriod : TIME := T#500ms;

Property Text: Period: %t[ms 'ms']

Property Text variable: PLC_PRG.tPeriod

Output: Period: 500 ms

%t[us]

Only for LTIME variables: microsecond definition (0–999)

Code: ltPeriod :LTIME := LTIME#1000D23H44M12S34MS2US44NS;

Property Text: 'Period': %t[dd.HH.m.s.ms.us.ns]

Property Text variable: PLC_PRG.ltPeriod

Output: Period: 1000.23.44.12.34.2.44

Hint: Overflow is permitted in the greatest time unit of a definition.

%t[ns]

Only for LTIME variables: nanosecond definition (0–999)

%t[t]

If the value is a time < 12h, then A is output; otherwise P is output.

Code: tClosed : TOD := TOD#17:17:17.17;

Property Text: Closed at %t[hh:mm t]

Property Text variable: PLC_PRG.tClosed

Output: Closed at 05:17 P

%t[tt]

If the value is a time < 12h, then AM is output; otherwise PM is output.

Code: tClosed : TOD := TOD#17:17:17.17;

Property Text: Closed at %t[hh:mm tt]

Property Text variable: PLC_PRG.tClosed

Output: Closed at 05:17 PM

%t[' ']

If character strings should be output which correspond to a format definition, then these have to be represented in single straight quotation marks.

TIME and LTIME values can be specified with integer values or with decimal places:

%t[<f><n>]

A number (<n>) which defines the number of decimal places of the time value follows the letters which define the time unit (<f>).

As a result, the hours, minutes, and seconds (for TIME values) and also the microseconds and nanoseconds (for LTIME values) can be specified or displayed as values with decimal places.

Note: Even if a decimal number is not desired for the input or display, at least the number “0” has to be specified to allow for fractional input.

Examples of the formating

%t[hh4] or %t[HH4]: The time can be specified/displayed with a hour definition of four decimal places.

%t[mm2] or %t[m2]: The time can be specified/displayed with a minute definition of four decimal places. Then for a value of t#1h20m15s, this leads to the following output: 80.25.

%t[ss0]: The time can be specified/displayed with a second definition without decimal places.

The format definitions can be represented in a series.

%t[HH:mm:ss:ms]

Output of the time

Code: dwTime : DWORD := 4294967295;

Property Text: Time: %t[HH:mm:ss:ms]

Property Text variable: PLC_PRG.dwTime

Output: Time: 23:59:59:999

%t[yyyy-MM-dd dddd]

Output of the date and day of the week

Code: dateSet : DATE := DATE#2016-02-12;

Property Text: Date: %t[yyyy-MM-dd dddd]

Property Text variable: PLC_PRG.dateSet

Output: Date: 2016-02-12 Friday

See also