Partial variable access

The expression conforms to the IEC 61131-3 standard.

Partial variable access is possible for IEC variables of data type BYTE, WORD, DWORD or LWORD (data type ANY und ANY_<Typ>).

Syntax:

<Variablenname>.%<Partieller Typ><Partieller Index>

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

<Variablenname>

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

<Partieller Typ>

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 permitted and behaves like a DWORD or LWORD depending on the pointer size.

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

<Partieller Index>

From 0 to the index maximum

For more information, see:

Use

Partial access can only be used for non-temporary variables (user-defined variables, fields, array accesses or dereferencing). This is not permitted 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.

Sample

bPartialVarB := GVL.nVar.%B0;
bPartialVarX := aArray[nIdx].%X0;
bPartialVarW := nTempVar.%W2;
bPartialVarD := pPointer^.%D2;
bPartialVarB := nVar.%W1.%B1

Partial access is not possible for function calls, index expressions, literals or properties.

Negative sample:

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

Index maximum of the partial types

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

Partial type

Access type

Maximum of the 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 <Partieller Typ> and must be selected from the following table.

Partial type

Expression type

X

BIT

B

BYTE

W

WORD

D

DWORD

L

LWORD

Addresses

It is permitted to form the address of a partial access expression of the partial type B, W, D and L.

It is not permitted to form the address of a partial access expression of partial type X.

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

Samples

ADR(nVar.%B0)
refVar REF= nVar.%W1

Negative sample:

ADR(nVar.%X0)
refVar REF= nVar.%X0