Allen-Bradley Logix5000 Reference Manual page 689

1756 controllogix, 1768 compactlogix, 1769 compactlogix, 1789 softlogix, 1794 flexlogix, powerflex 700s with drivelogix
Hide thumbs Also See for Logix5000:
Table of Contents

Advertisement

Example 2:
If you want this
A user-defined data type (structure) stores the following information
about an item in your inventory:
·Barcode ID of the item (string data type)
·Quantity in stock of the item (DINT data type)
An array of the above structure contains an element for each
different item in your inventory. You want to search the array for a
specific product (use its bar code) and determine the quantity that is
in stock.
1. Get the size (number of items) of the Inventory array and store the
result in Inventory_Items (DINT tag).
2. Initialize the position tag to 0.
3. If Barcode matches the ID of an item in the array, then:
a. Set the Quantity tag = Inventory[position].Qty. This produces the
quantity in stock of the item.
b. Stop.
Barcode is a string tag that stores the bar code of the item for
which you are searching. For example, when
position = 5, compare Barcode to Inventory[5].ID.
4. Add 1 to position.
5. If position is ≤ to (Inventory_Items -1), repeat
element numbers start at 0, the last element is 1 less than the
number of elements in the array.
Otherwise, stop.
Enter this structured text
SIZE(Inventory,0,Inventory_Items);
For position:=0 to Inventory_Items - 1 do
End_for;
3
and 4. Since
Rockwell Automation Publication 1756-RM003N-EN-P - October 2011
Structured Text Programming
If Barcode = Inventory[position].ID then
Quantity := Inventory[position].Qty;
Exit;
End_if;
Appendix C
689

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents