Skip to main content

Partial Variable Access

The expression complies with the IEC 61131-3 standard.

Partial variable access is possible in the case of IEC variables of data type BYTE, WORD, DWORD or LWORD (data type ANY, ANY_<type> ).

Syntax:

<variable name>. % <partial type> <partial index>

A space is allowed after the dot operator (.). No spaces are allowed after the percent sign (%) and after the partial type.

<variable name>

Name of the ANY_BIT variable of the type BYTE, WORD, DWORD, or LWORD

<partial type>

X for BIT access

B for BYTE access

W for WORD access

D for DWORD access

L for LWORD access

Access to __XWORD is also allowed and behaves like a DWORD or LWORD depending on the pointer size.

Access to BOOL is not allowed even if the BOOL data type is part of the ANY_BIT types.

<partial index>

From 0 to the index maximum

Usage

Partial access can be used only for non-temporary variables (user-defined variables, fields, array accesses, or dereferencing). This is not allowed for temporary results or literals.

The expression itself is not temporary and can be used as an expression in REFERENCE TO or as an ADR operator.

Example 200. Example
// Implementation
PartialVarB := GVL.Variable.%B0;
PartialVarX := array[idx].%X0;
PartialVarW := tempVariable.%W2;
PartialVarD := ptr^.%D2;
PartialVarB := variable.%W1.%B1

Partial access is not possible in the case of function calls, index expressions, literals, or properties.

Negative example:

FunctionCall().%B0
(1+index).%B0
(DWORD#16#12345678).%B0
Property.%B0


Index maximum of partial types

Partial access is possible only if the called expression has a conforming type and the partial index is less than or equal to the maximum partial index. Otherwise a compiler error is reported.

Partial Type

Access Type

Maximum of Partial Index

X

BYTE

7

WORD

15

DWORD

31

LWORD

63

B

BYTE

0

WORD

1

DWORD

3

LWORD

7

W

BYTE

Not supported

WORD

0

DWORD

1

LWORD

3

D

BYTE

Not supported

WORD

Not supported

DWORD

0

LWORD

1

L

BYTE

Not supported

WORD

Not supported

DWORD

Not supported

LWORD

0

Expression with partial access

The type of a partial access expression depends only on <partial type> and has to be selected using the following table.

Partial Type

Type of Expression

X

BIT

B

BYTE

W

WORD

D

DWORD

L

LWORD

Addresses

It is allowed to create the address from a partial access expression of partial type B, W, D, and L.

It is not allowed to create the address from a partial access expression of partial type X.

It is not allowed to assign a partial access expression of type BIT to a VAR_INOUT variable.

Example 201. Examples
ADR(var%.B0)
referenceVariable REF= var.%W1

Negative example:

ADR(var.%X0)
ref REF= var.%X0