Constant expressions can be used in all languages for assigning a variable with a value. All constant expressions have a well-defined data type according to their semantics. If you program an operation between variables and constant expressions having inconsistent data types, it leads to syntactic errors when the program is compiled.
Below is the list of prefixes according to possible data types:
Table 5-1: List of Prefixes for Constant expressions
Below are some examples of valid constant expressions:
| TRUE | TRUE Boolean expression |
| FALSE | FALSE Boolean expression |
| SINT#127 | small integer |
| INT#2000 | 16 bit integer |
| 123456 | DINT (32 bit) integer |
| 16#abcd | DINT integer in hexadecimal basis |
| 8#34712 | DINT integer in octal basis |
| 2#1000100 | DINT integer in binary basis |
| LINT#1 | long (64 bit) integer having the value "1" |
| 0.0 | 0 expressed as a REAL number |
| 1.002E3 | 1002 expressed as a REAL number in scientist format |
| LREAL#1E-200 | Double precision real number |
| T#23h59m59s999ms | maximum TIME value |
| TIME#0s | null TIME value |
| T#1h123ms | TIME value with some units missing |
| 'hello' | character string |
| 'name$Tage' | character string with two words separated by a tab |
| 'I$'m here' | character string with a quote inside (I'm here) |
| 'x$00y' | character string with two characters separated by a null character (ASCII code 0) |
Below are some examples of typical errors in constant expressions
| BooVar := 1; | 0 and 1 cannot be used for Booleans |
| 1a2b | basis prefix ("16#") omitted |
| 1E-200 | "LREAL#" prefix omitted for a double precision float |
| T#12 | Time unit missing |
| 'I'm here' | quote within a string with "$" mark omitted |
| hello | quotes omitted around a character string |
Additionally, there are pre-defined constants. See Use the Defines List for information about Internal and user-defined Defines.
|
Copyright © 2015 Kollmorgen™ |
|