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,879
I´ve being trying wrap head around FOR loops.. When and what can this be used for? I´ve mostly seen it move data, resettting arrays etc. I made a...
Replies
7
Views
148
Hi! When is CASE preffered? CASE uses a numreric variable for the cases and doesnt handle BOOL, but this can be done with numreric and bool using...
Replies
4
Views
135
Hello, doing switch from FBD to ST. First task is converting my old work. How do you sum variables? For example, Interlock1, interlocl2 and...
Replies
5
Views
200
Hello, I am using studio 5000 pro and am trying to figure out the structured text. Here's my scenario: An operator scans a barcode, the barcode...
Replies
15
Views
359
Back
Top Bottom