Structured text, UDTs and arrays in Logix5000

technolog

Lifetime Supporting Member
Join Date
May 2015
Location
Ohio
Posts
320
I'm trying to do my first ever structured text routine and failing miserably. Just to make things interesting, it's also my first foray into UDTs too.

I've created a UDT called Recipe with 71 member tags (if that's the correct term) to hold recipe values. I've created an array called Recipe_DB of data type Recipe of 250 elements to hold the actual recipe data.

I have to scan a barcode containing the part number. The part number is stored as a string data type I've created that has room for the 8 characters of the part number plus a CR - 9 SINTs in total.

My structured text routine should be a simple for loop, stepping through the 250 recipes checking for the bar code part number being equal to the recipe part number then copying the Recipe_DB that matches to the Working_recipe

I'm getting the following errors when I try to verify the routine:

Verifying routine: MainProgram - Recipe_retrieval...
Error: (Pend), Line 2: Missing reference to array element.
Error: (Pend), Line 3, 'Working_recipe': Assignment to tag of specified data type invalid.
Complete - 2 error(s), 0 warning(s)

I'm guessing the errors stem from the way I'm addressing the strings or arrays or both. Can some kind soul cast their eye over the attached program and offer some guidance, please?
 
Last edited:
Appears you are missing an array specifier on your .Part_Number, I didn't look to closely to understand your datatype usage, I assume there is some additional work you will need to do.

Use the COP instruction to copy your recipe data.

Code:
FOR i:= 1 TO 250 DO
    IF Barcode_Accepted = Recipe_DB[i].Part_Number[B][0][/B] THEN
        COP(Recipe_DB[i], Working_recipe, 1);
    END_IF;
END_FOR;
 
I realized I'd actually created an array of [8] part numbers in my Recipe data. I got rid of the array and used the COP() command and everything verifies okay now. So thanks for that.
 
An Array of 250 is 0-249 not 1-250. Maybe your error is telling you it cannot find element 250. Increase your array size to 251 if you wish to use 1-250
 
Yes, I caught that. In my defense, my boss wrote the initial code and for some unfathomable reason, he has a dislike of starting for loop counters at zero :oops:

An Array of 250 is 0-249 not 1-250. Maybe your error is telling you it cannot find element 250. Increase your array size to 251 if you wish to use 1-250
 

Similar Topics

Hello All, Figured I would join the forum after looking for some information on the web and under the search function of this site. I figured i...
Replies
3
Views
2,847
I have an expression in a structured text routine of a Logix controller that looks more or less like the following: ResultInteger := Integer1 *...
Replies
13
Views
389
Good evening. I display the step number of a SFC on a display. Sometimes, on a trip, it goes quickly through many steps and I need to prove to...
Replies
1
Views
127
I am trying to set up a piece of equipment with a Horner HE-X4R. I'd like to use structured text and so far I'm just trying to get a basic On/off...
Replies
0
Views
70
Good morning. I'm doing a rehab and I need to recycle some part of the old code that won't change and that I need. This is a calculation that...
Replies
22
Views
1,359
Back
Top Bottom