Menu
CoddyTech

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_VAR

BOOL, 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 icon

Challenge

Easy
  • Declare a BOOL variable Ready in a VAR block.
  • Make Ready TRUE while SW1 and SW2 are both on.
  • Light Green while Ready is TRUE, and Red while it is not.

Try it yourself

VAR
    // declare Ready here
END_VAR

// Ready, then the two lamps
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Structured Text

Practice on your own: PLC playground