How to Remove Initial Letter from String in Studio 5000 Professional

Question:

Hello, I am currently utilizing Studio 5000 Professional and exploring the implementation of structured text. In my current situation, an operator scans a barcode which is then processed, prompting the PLC to search an array for the corresponding part number. If the number is found, the PLC will retrieve the associated elements in the subtag. However, if the part number is not found, a new subtag with the necessary elements will be created. The challenge arises when some part numbers are identical, with the only variation being the presence of a "P" at the beginning. For instance, the tag array may list a number as 11223344, but the operator scans a barcode labeled as "P11223344", resulting in the creation of a new tag. As a result, I have encountered over 90 duplicate tags caused solely by this added letter. I am seeking a solution to remove the initial letter from the string only if it is a "P". Initially, I believed structured text was the best approach for this task, but I am open to exploring alternative methods. This issue has been puzzling me for some time now, and I would appreciate any guidance on how to resolve it effectively.

Top Replies

Achieving this task in Ladder logic may require approximately 2 instructions. Use the EQU instruction on the initial element of the .DATA section within the string tag to check for the presence of the letter "P", followed by a MID instruction to extract the remaining value to a different location or back to the original one.

Apologies for the confusion, it requires 3 steps: Keep in mind that 80 represents the ASCII value for the letter "P". If needed, you can switch the EQU to LIM to enable the removal of non-numeric characters.

Presenting the code in Structured Text (ST), potentially marking the debut of my first ST script created solely in Allen-Bradley (AB) programming language.

When analyzing Scan_PNUM.DATA[0], it reveals the presence of the letter "P". I will utilize the barcode scanner to convert the ASCII to Allen Bradley format. I have a query - If I decrease the value by 1 in Scan_PNUM.len, will it affect the front end or the backend? I aim to prevent any leading empty space within the string. Thanks for the guidance on configuring it to examine the .DATA[] segment of the tag.

In a forum post, joseph_e2 explained that instead of using three instructions, users can optimize their code by reducing it to just two instructions. By swapping out the MID instruction for the more efficient DELETE instruction, users can streamline their code for better performance. Click to expand to learn more about this optimization tip.

Hi, a good approach here would be to use the STRING function MID. MID(string, start, length) can resolve your issue by checking if the first character of your string is "P" and if so, creating a new string with everything after the first character. In your case, for an operator input "strInput," the code would look something like this: `IF MID(strInput, 1, 1) = 'P' THEN strInput := MID(strInput, 2, LEN(strInput) -1); END_IF;` This should help eliminate the duplicates. Good luck!

More Replies →

Streamline Your Asset Management
See How Oxmaint Works!!

✅   Work Order Management

✅   Asset Tracking

✅   Preventive Maintenance

✅   Inspection Report

We have received your information. We will share Schedule Demo details on your Mail Id.

To add a comment, please sign in or register if you haven't already..   

Frequently Asked Questions (FAQ)

FAQ: 1. Question: How can I remove the initial letter from a string in Studio 5000 Professional, specifically if it is a "P"?

Answer: Answer: One approach to achieve this is by using structured text programming in Studio 5000 Professional. You can write logic to check if the first character of the string is a "P" and then remove it if the condition is met.

FAQ: 2. Question: What can I do to prevent the creation of duplicate tags caused by variations in part numbers like "P11223344" and "11223344" in Studio 5000 Professional?

Answer: Answer: To prevent the creation of duplicate tags, you can implement a validation step in your PLC program to check for such variations in part numbers. By detecting and handling cases where the only difference is the initial "P", you can avoid creating unnecessary tags.

FAQ: 3. Question: Are there alternative methods to address the challenge of removing the initial letter from a string in Studio 5000 Professional other than using structured text?

Answer: Answer: While structured text may be a suitable approach for this task, you can also explore other methods such as using string manipulation functions or creating custom user-defined functions in ladder logic to achieve the desired outcome. Experimenting with different techniques can help you find the most efficient solution for your specific scenario.

Ready to Simplify Maintenance?

Join hundreds of satisfied customers who have transformed their maintenance processes.
Sign up today and start optimizing your workflow.

Request Demo  â†’