Shortening a string (pulling only a few characters out of it)

Brandon_K

Member
Join Date
Mar 2016
Location
Pittsburgh, PA
Posts
150
Hey guys.

On all of the new builds we're doing I'm trying to get the program revision to display on the onboard OELD display. I'm guilty of not always manually updating it.

The PLC (AD Productivity 2000) has a 50 character system string that contains the program name as I have saved / named it on the PC. So typically it's something like "Customer_Name_Game_Name_Rx.xx.adpro". The revision is always the last 5 characters of the name, before the .adpro extension.

How can I go about pulling just the revision number out of that string? I basically need to drop the last 6 characters (.adpro), keep the next 5 (Rx.xx) and drop everything previous to that.

From there I can copy or repack it into a string usable on the OLED display.
 
I think you will need to make use of the SLEN (string length) function to find the length of the string then use the result to compute the start character index for use in the EXTS (Extract String) function.

I have used the OLED display quite a bit but I have not used those two functions I am suggesting, I just read about them in the software help file.
 
Brilliant! Thanks OkiePC! I've been working with the P2K for a while now and I don't remember ever coming across those instructions. Thanks!

I've attached a screenshot of my code should anyone want to replicate something similar.

Theory;

SLEN determines how many characters the total string is

MATH; Subtracts 10 from the output of the SLEN instruction as the tail of the filename is always the same. This gives me a starting point to extract from.

EXTS; Extracts 5 characters from "x" characters in (determined by SLEN and MATH)

stringextract.jpg
 

Similar Topics

All, I am trying to reset timers when a Work Order change occurs. The Work Order comes in as a string and I am comparing it to a tag...
Replies
2
Views
100
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
292
I am creating a global object in FTView SE 13. I want to have a string read from the PLC and display (in this case the tagname). So lets say...
Replies
4
Views
195
So I had an odd request from a customer for the above. I have written the logic and tested it all in one PLC with only using 7 outputs and 7...
Replies
15
Views
450
Hello Inside a FB, I´m trying to transfer a string from a DB to a IN_OUT var that was define as a UDT. The problem is that i can´t determine the...
Replies
4
Views
162
Back
Top Bottom