Placeholders with Format Definition in the Output Text

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

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

See also

Printing integers

%d

%i

Printing a variable (integer data type) as a decimal number

Code: iCounter : INT := 12;

Property Text: Value: %i

Property Text variable: PLC_PRG.iCounter

Output: Value: 12

%b Printing a variable (integer data type) as a binary number

Code: byCode : BYTE := 255;

Property Text: Coding: %b

Property Text variable: PLC_PRG.byCode

Output: Coding: 11111111

%o Printing a variable (integer data type) as an 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 Printing a variable (integer data type with maximum 32 bits) as an 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 a 64-bit variable (LWORD, LINT, ULINT) as a 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 Printing a variable (integer data type) as an unsigned decimal number

Code: uiNumber : UINT := 1234;

Property Text: Number: %u

Property Text variable: PLC_PRG.uiNumber

Output: Number: 1234

Printing 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 decimal places

Code: rWeight : REAL := 12.1

Property Text: Weight: %2.3f

Property Text variable: PLC_PRG.rWeight

Output: Weight: 12.100

%e Printing a 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

Printing text

%c Printing a single character in ASCII

Code: bChar := 16#41;

Property Text: Key: %c

Property:guilabel:Text variable: PLC_PRG.bChar

Output: Key: A

%s Printing a character string

Code: strName := 'Paul Smith';

Property Text: Name: %s

Property Text variable: PLC_PRG.strName

Output: Name: Paul Smith

Printing the percent sign

%% Printing the percent sign in a 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%

Printing the date and time

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

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

Date and time formats
%t[yyyy] Years with century (4 digits)

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] Years 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] Years 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] Months as a 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] Months as an 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] Months as a 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] Months as a 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] Days of week as a number (1=Monday to 7=Sunday)

Code: iDay : INT := 7;

Property Text:: Day: %t[ddddd]

Property Text variable: PLC_PRG.iDay

Output: Day: 7

%t[dddd] Days of week as a full name

Code: iDay : INT := 7;

Property Text:: Day: %t[dddd]

Property Text variable: PLC_PRG.iDay

Output: Day: Sunday

%t[ddd] Days of week as an abbreviated name

Code: iDay : INT := 7;

Property Text:: Day: %t[ddd]

Property Text variable: PLC_PRG.iDay

Output: Day: Sun

%t[dd] Days in month as a number (01 – 31)

Code: iDay : INT := 1;

Property Text:: Day: %t[dd]

Property Text variable: PLC_PRG.iDay

Output: Day: 01

%t[d] Days in month as a number (1 – 31)

Code: iDay : INT := 1;

Property Text:: Day: %t[d]

Property Text variable: PLC_PRG.iDay

Output: Day: 1

%t[jjj] Days in year as a 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] Hours 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] Hours in 12-hour format (01-12)

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

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

Property Text variable: PLC_PRG.todEnd

Output: Ends at 17:00 o'clock

     
%t[mm] Minutes with leading zeros (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 zeros (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 zeros (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 zeros (0-59)

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

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

Property Text variable: PLC_PRG.tPeriod

Output: Period: 5m3s

%t[ms] Milliseconds without leading zeros (0-999)

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

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

Property Text variable: PLC_PRG.tPeriod

Output: Period: 500ms

%t[us] For LTIME variables only: 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

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

%t[ns] For LTIME variables only: nanosecond definition (0-999)
     
%t[t]

If the value is a time < 12h, then A is printed;

otherwise P is printed.

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

Property Text: Closed at %t[hht]

Property Text variable: PLC_PRG.tClosed

Output: Closed at 5P

%t[tt] If the value is a time < 12h, then AM is printed; otherwise PM is printed.

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

Property Text: Closed at %t[hh tt]

Property Text variable: PLC_PRG.tClosed

Output: Closed at 5 PM

     
%t[' '] If character strings should be printed that correspond to a format definition, then these must be represented in single straight quotation marks.  
 
The format definitions can be represented in a series.
%t[HH:mm:ss:ms] Printing the complete 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] Printing 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