Variables in VAR
Part of the Structured Text section of Coddy's PLC Programming journey. Lesson 5 of 17.
A memory bit in text is a variable. You declare it at the top of the program, between VAR and END_VAR, with its name and its type:
VAR
Ready : BOOL;
Count : INT := 0;
END_VARBOOL, INT and DINT you know from ladder tags. Two more: REAL holds a number with a fraction, like 59.6, and TIME holds a length of time, like T#5s. := 0 gives a starting value; without one a variable starts at FALSE or 0.
The machine's inputs and outputs are already declared for you. Declare only your own variables, then use them like any tag:
Challenge
Easy- Declare a BOOL variable
Readyin a VAR block. - Make Ready TRUE while
SW1andSW2are both on. - Light
Greenwhile Ready is TRUE, andRedwhile it is not.
Try it yourself
VAR
// declare Ready here
END_VAR
// Ready, then the two lamps
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Structured Text
1From Rungs to Text
Your First StatementAND, OR and NOTThe Seal-In in TextIF and THENVariables in VARPractice on your own: PLC playground