Many times in PLC programming we want to create a single function that can be used for many different cases. Here is a simple example.
I have 15 tanks that are all of different sizes when full. The size of Tank 1 (in liters) is entered into N7:1; the size of Tank 2 (in liters) is entered into N7:2; the size of Tank 3 (in liters) is entered into N7:3, and so on. The level (in %) for each tank is in another data file: The level of Tank 1 is entered into N8:1; the level of Tank 2 is entered into N8:2; the level of Tank 3 is entered into N8:3, and so on.
In my PLC code, I may have an equation to calculate the current amount in each tank, which is the level in %, as indicated in the N8 data file for each tank multiplied by the total volume of the tank in the N7 data file. I could code 15 rungs to do this calculation for each tank (one equation per tank), OR, I could use a variable called TANK_NUM to indirectly calculate the current volume in the tank.
Volume = N8:[TANK_NUM] * N7:[TANK_NUM]
Now, when I want to determine the current level in a tank, I set the variable TANK_NUM equal to a number from 1 to 15, each representing a different tank. Then I call the subroutine or function that performs the calculation. So, if the Tank number is 7, then the equation will calculate the volume as;
Volume = N8:7 * N7:7.
When the volume equation is called, it replaces the variable TANK_NUM with the actual value of TANK_NUM.