How can you compare variables of the type WORD or DWORD with each other?
Two variables of the type WORD are to be compared with each other in an S7-SCL program, for example, the variables:
However, the comparison operations with ">", "<" and "<>" are not permitted in S7-SCL with variables of the type WORD or DWORD and in the case of a statement, for example with
Compare_Var:= Max_Var > Min_Var;
the error message "Invalid operand types" is displayed during compilation. Such comparison operations are permitted only with variables of the type DINT. You must therefore first program data type conversion from WORD to DWORD and from DWORD to DINT using the conversion functions.
|No.||Procedure for programming the comparison operation|
|1||First of all, declare two variables each for the two variables "Max_Var" and "Min_Var" to be converted. For example for the variable "Max_Var":
|2||Then program the first data type conversion from WORD to DWORD using the conversion function of Class A:
|3||Using the second conversion function of Class B, convert from DWORD to DINT:
|4||The conversions described in points 2 and 3 must also be programmed for the variables for the second comparison variable "Min_Var". You can now write an instruction such as "Compare_Var:= Max_Y > Min_Y;", which is compiled by the compiler, for the purposes of a comparison operation.|
Greater than or equal to, Less than or equal to, Does not equal