If the VAR_IN_OUT CONSTANT variable is of type STRING/WSTRING, a variable, a constant variable, or a constant (literal) can be transferred when the programming block is called.Transfer of properties is not permitted.Write access to the VAR_IN_OUT CONSTANT variable is not permitted.VAR_IN_OUT CONSTANT variables are declared without assigning an initialization value. Direct assignment of the bit variable to the VAR_IN_OUT input (error) and assignment using an intermediate variable (workaround): PROGRAM MAINĮND_VAR // Error C0201: Type 'BIT' doesn't correspond to the type 'BOOL' of VAR_IN_OUT 'bInOut'Ī VAR_IN_OUT CONSTANT variable serves as a constant transfer parameter that can be read but not written to. Sample of a workaround for assigning a bit variable to a VAR_IN_OUT input:ĭeclaration of the bit variables (bBit0): VAR_GLOBALįunction block with VAR_IN_OUT input bInOut: FUNCTION_BLOCK FB_Test This would not be the case, for example, if the property returned the reference to a temporary variable.įunction block FB_Sample FUNCTION_BLOCK FB_SampleįbSample() // NOK: not possible as the VAR_IN_OUT variable is not assigned in this FB callįbSample.bInOut := bTest // NOK: direct access to VAR_IN_OUT variable from the outside not possible Note, however, that the property may only return an address via REFERENCE that is valid beyond the property call. No property can be transferred to a VAR_IN_OUT or VAR_IN_OUT CONSTANT variable.Įxception: An assignment to VAR_IN_OUT (CONSTANT) is possible if the property has the return type REFERENCE. Further information can be found at the bottom of this page. At the most, however, the string length of the VAR_IN_OUT CONSTANT variable will be processed. If a character string is transferred as a variable or as a constant to a formal VAR_IN_OUT CONSTANT variable, the string length can vary. Transferring strings to VAR_IN_OUT CONSTANT
Transferring bit variables: A bit variable cannot be transferred directly to a VAR_IN_OUT variable but requires an intermediate variable.This problem does not occur with VAR_OUTPUT CONSTANT parameters. Otherwise the transferred string can be manipulated unintentionally. Transferring string variables: If a string variable is transferred as an argument, the actual variable and the formal variable should have the same length.This only works for VAR_INPUT and VAR_OUTPUT variables. Read/write access from outside: VAR_IN_OUT variables cannot be read or written directly from outside via.This means that a programming block uses its VAR_IN_OUT variables in the same way as the calling programming block uses its variables. When the programming block is exited, any changes made are thus retained. Read/write access within the programming block: Any write access to the variable within the programming block has an effect on the transferred variable.It is not possible to directly specify a constant (literal), a constant variable or a bit variable as an argument. The internal value of the referential variables is a memory address to the actual value (transfer as pointer, call by reference). No copy is created at runtime during the parameter passing, but the formal variable receives a reference to the actual variable transferred from outside. Call: When the programming block is called, the formal VAR_IN_OUT variable receives the actual variable (referred to as pass-through variable) as an argument.The VAR_IN_OUT variable can be read and written. A constant of the declared data type can optionally be assigned as the initialization value. : FUNCTION | FUNCTION_BLOCK | METHOD | PRGĪn input and output variable can be declared in the programming blocks PRG, FUNCTION_BLOCK, METHOD or FUNCTION in the declaration section VAR_IN_OUT. The VAR_IN_OUT variables of a function block must be assigned when the function block is called. A VAR_IN_OUT variable is an input and output variable that is part of a function block interface and serves as a formal pass-through parameter.