0% found this document useful (0 votes)
3 views1 page

Structure Text Programming - Codesys 4

The document provides examples of variable declarations in a programming context, including various data types such as WORD, INT, BOOL, REAL, and STRING. It also illustrates how to initialize variables and use arrays, along with examples of literal values for different number types. Additionally, it explains the use of underscores in numeric literals for better readability.

Uploaded by

edlistianto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Structure Text Programming - Codesys 4

The document provides examples of variable declarations in a programming context, including various data types such as WORD, INT, BOOL, REAL, and STRING. It also illustrates how to initialize variables and use arrays, along with examples of literal values for different number types. Additionally, it explains the use of underscores in numeric literals for better readability.

Uploaded by

edlistianto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

332

Text Program Line Description

VAR AT %B3:0 : WORD; END_VAR a word in bit memory


VAR AT %N7:0 : INT; END_VAR an integer in integer memory
VAR RETAIN AT %O:000 : WORD ; END_VAR makes output bits retentive
VAR_GLOBAL A AT %I:000/00 : BOOL ; END_VAR variable ‘A’ as input bit
VAR_GLOBAL A AT %N7:0 : INT ; END_VAR variable ‘A’ as an integer
VAR A AT %F8:0 : ARRAY [0..14] OF REAL; END_VAR an array ‘A’ of 15 real values
VAR A : BOOL; END_VAR a boolean variable ‘A’
VAR A, B, C : INT ; END_VAR integers variables ‘A’, ‘B’, ‘C’
VAR A : STRING[10] ; END_VAR a string ‘A’ of length 10
VAR A : ARRAY[1..5,1..6,1..7] OF INT; END_VAR a 5x6x7 array ‘A’ of integers
VAR RETAIN RTBT A : ARRAY[1..5,1..6] OF INT; a 5x6 array of integers, filled
END_VAR with zeros after power off
VAR A : B; END_VAR ‘A’ is data type ‘B’
VAR CONSTANT A : REAL := 5.12345 ; END_VAR a constant value ‘A’
VAR A AT %N7:0 : INT := 55; END_VAR ‘A’ starts with 55
VAR A : ARRAY[1..5] OF INT := [5(3)]; END_VAR ‘A’ starts with 3 in all 5 spots
VAR A : STRING[10] := ‘test’; END_VAR ‘A’ contains ‘test’ initially
VAR A : ARRAY[0..2] OF BOOL := [1,0,1]; END_VAR an array of bits
VAR A : ARRAY[0..1,1..5] OF INT := [5(1),5(2)]; an array of integers filled with 1
END_VAR for [0,x] and 2 for [1,x]

Figure 265 Variable Declaration Examples

Basic numbers are shown in Figure 266. Note the underline ‘_’ can be ignored, it can be used to
break up long numbers, ie. 10_000 = 10000. These are the literal values discussed for Ladder Logic.

number type examples

integers -100, 0, 100, 10_000


real numbers -100.0, 0.0, 100.0, 10_000.0
real with exponents -1.0E-2, -1.0e-2, 0.0e0, 1.0E2
binary numbers 2#111111111, 2#1111_1111, 2#1111_1101_0110_0101
octal numbers 8#123, 8#777, 8#14
hexadecimal numbers 16#FF, 16#ff, 16#9a, 16#01
boolean 0, FALSE, 1, TRUE

Figure 266 Literal Number Examples

Character strings defined as shown in Figure 267.

You might also like