Register Now


Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Captcha Click on image to update the captcha .


Register Now

register content

PLC Programming Example

We can use the “FOR DO” command structure to find the sought value in an array. In the example below, I will explain how to run the “FOR DO” command in the STL language that I have prepared for you and understand the index number of a number in the array or whether this number is in the array.

The “SIZE” instruction is an instruction that returns the number of elements of the parameterized array.
If you know how many elements the array has, you can enter the part inside the “FOR DO” loop.
If you want to write parametrically without errors, you can use the “SIZE” command.

plc programming FORDO STL plc

Size(BarcodeArray,0,SizeCount); command returns 100 to SizeCount tag because BarcodeArray array has 100 elements.
The data type of the SizeCount tag is DINT.

BarcodeFound :=0; // if the barcode value we are looking for is found, this tag will be 1.  The data type is boolean.
Barcode_Index:=0; // If the barcode value we are looking for is found in which index, this value will show that index number. Data type DINT.

initialize their values ​​to zero.

The data type of the B_Index tag is Integer
The “for” loop will start from zero and do the next action after the “do” line up to 99 . In this range, we are looking for the number of BarcodeSearch in the BarcodeArray array with the if loop.
The data type of the BarcodeSearch tag is DINT.
If tag value is found,
BarcodeFound := 1; so the barcode is found and
Barcode_Index :=B_Index; We print the index number found in the Barcode_Index tag.
And finally, we close the “if” and “for” loops with “end”.
for B_Index := 0 to SizeCount -1 do

if BarcodeArray[B_Index]=BarcodeSearch then
BarcodeFound := 1;
Barcode_Index :=B_Index;

plc programming barcodearraysearch plc

In the ladder programming part,
If the barcode number we wrote in the BarcodeSearch section is not equal to the previous value, we call the For-Do routine.

plc programming BarcodeSearch plc


You can edit this part as you wish. If you have questions, you can use the comments section or our plc forum.