The leader in industrial automation and control solutions

Sample Macro Code

“for” statement and other expressions (arithmetic, bitwise shift, logic and comparison)

macro_command main()

int a[10], b[10], i

b[0] = (400 + 400 << 2) / 401

b[1] = 22 *2 – 30 % 7

b[2] = 111 >> 2

b[3] = 403 > 9 + 3 >= 9 + 3 < 4 + 3 <= 8 + 8 == 8

b[4] = not 8 + 1 and 2 + 1 or 0 + 1 xor 2

b[5] = 405 and 3 and not 0

b[6] = 8 & 4 + 4 & 4 + 8 | 4 + 8 ^ 4

b[7] = 6 – (~4)

b[8] = 0x11

b[9] = 409

for i = 0 to 4 step 1

if (a[0] == 400) then

GetData(a[0], “Device 1”, 4x, 0,9)

GetData(b[0],”Device 1″, 4x, 11,10)

end If

next i

end macro_command

“while”, “if” and “break” statements

macro_command main()

int b[10], i

i = 5

while i == 5 – 20 % 3

GetData(b[1], “Device 1”, 4x, 11, 1)

if b[1] == 100 then

break

end if

wend

end macro_command

Global variables and function call

char g

sub int fun(int j, int k)

int y

SetData(j, “Local HMI”, LB, 14, 1)

GetData(y, “Local HMI”, LB, 15, 1)

g = y

return y

end Sub

macro_command main()

int a, b, i

a = 2

b = 3

i = fun(a, b)

SetData(i, “Local HMI”, LB, 16, 1)

end macro_command

“if” statement

macro_command main()

int k[10], j

for j = 0 to 10

k[j] = j

next j

if k[0] == 0 then

SetData(k[1], “Device 1”, 4x, 0, 1)

end if

if k[0] == 0 then

SetData(k[1], “Device 1”, 4x, 0, 1)

else

SetData(k[2], “Device 1”, 4x, 0, 1)

end if

if k[0] == 0 then

SetData(k[1], “Device 1”, 4x, 1, 1)

else if k[2] == 1 then

SetData(k[3], “Device 1”, 4x, 2, 1)

end If

if k[0] == 0 then

SetData(k[1], “Device 1”, 4x, 3, 1)

else if k[2] == 2 then

SetData(k[3], “Device 1”, 4x, 4, 1)

else

SetData(k[4], “Device 1”, 4x, 5, 1)

end If

end macro_command

“while” and “wend” statements

macro_command main()

char i = 0

int a[13], b[14], c = 4848

b[0] = 13

while b[0]

a[i] = 20 + i * 10

if a[i] == 120 then

c =200

break

end if

i = i + 1

wend

SetData(c, “Device 1”, 4x, 2, 1)

end macro_command

“break” and “continue” statements

macro_command main()

char i = 0

int a[13], b[14], c = 4848

b[0] = 13

while b[0]

a[i] = 20 + i * 10

if a[i] == 120 then

c =200

i = i + 1

continue

end if

i = i + 1

if c == 200 then

SetData(c, “Device 1”, 4x, 2, 1)

break

end if

wend

end macro_command

Array

macro_command main()

int a[25], b[25], i

b[0] = 13

for i = 0 to b[0] step 1

a[i] = 20 + i * 10

next i

SetData(a[0], “Device 1”, 4x, 0, 13)

end macro_command

Syntax for placing quotation marks in a string applies to variable declaration and function’s argument.

macro_command main()

char data[40]= “”Note” “

StringCopy(“This is a “test” for Maple”, data[7])

//The string contains “Note” This is a “test” for Maple

end macro_command