
kewakl (Customer) asked a question.
Can we get 'local' variables in structured text like we have in UDI?
Is it possible?
Thank you.

kewakl (Customer) asked a question.
Can we get 'local' variables in structured text like we have in UDI?
Is it possible?
Thank you.

Yes, but I want local variables without the UDI.
As in the snippet below, three defined variables are local-scoped that only live during the execution of this task, and require no Tag Database assignments.
Currently, these variables are global tags that have no use outside this ST task.
I know it is a big ask, but it minimizes wasted global tags with no other use.
Thanks for any considerations.
**NOTE:
I have not tested and cannot test the following snippet.
It contains unsupported keywords and functionality.
It is for demonstration purposes only.
- LOCAL TempStr AS STRING; // temporary string to hold InputString with any replacements
- LOCAL i AS INTEGER16; // for loop index
- LOCAL res AS INTEGER16; // result of FIND instruction
- LOCAL flag AS BOOLEAN; // flag indicating whether a replacement was made
- // and if OutString needs to be updated
-
- OutString := "";
- TempString := InString;
- flag := FALSE;
-
- FOR i := 1 TO SLEN( TempStr ) by 1 DO
- res := ( FIND( TempStr , Oldchar ) );
- IF res <> 0 THEN
- flag := TRUE;
- OutString := REPLACE( TempStr , NewChar, 1, res );
- TempString := OutString;
- ELSE
- EXIT;
- END_IF;
- END_FOR;
-
- IF flag = TRUE THEN
- OutString := TempString;
- ELSE
- // OutString := "";
- END_IF;
Thank you for the thorough description — this level of detail is invaluable in helping our Product Development Team fully evaluate your request. I will forward your feedback to them for review and consideration


Interesting coincidence...
I have been working on a single-character find/replace routine for another guy here.
Then you drop ST that includes REPLACE()

I agree this is a useful feature. KV-Studio for Keyence PLCs have it, there is a local variable table for each routine but also If you want to assign a local temporary tag you use the @ symbol in front of the variable name.
Copyright © 1999-2023 AutomationDirect. ALL RIGHTS RESERVED
Thank you for the thorough description — this level of detail is invaluable in helping our Product Development Team fully evaluate your request. I will forward your feedback to them for review and consideration