kewakl (Customer) asked a question.

PAC Suite Structured Text - request

Can we get 'local' variables in structured text like we have in UDI?

Is it possible?

Thank you.


ADC Community_02 likes this.
  • ADC Community_02 (Automationdirect.com)

    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

    Selected as Best
    • kewakl (Customer)

      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.

      1. LOCAL TempStr AS STRING; // temporary string to hold InputString with any replacements
      2. LOCAL i AS INTEGER16; // for loop index
      3. LOCAL res AS INTEGER16; // result of FIND instruction
      4. LOCAL flag AS BOOLEAN; // flag indicating whether a replacement was made
      5. // and if OutString needs to be updated
      6.  
      7. OutString := "";
      8. TempString := InString;
      9. flag := FALSE;
      10.  
      11. FOR i := 1 TO SLEN( TempStr ) by 1 DO
      12. res := ( FIND( TempStr , Oldchar ) );
      13. IF res <> 0 THEN
      14. flag := TRUE;
      15. OutString := REPLACE( TempStr , NewChar, 1, res );
      16. TempString := OutString;
      17. ELSE
      18. EXIT;
      19. END_IF;
      20. END_FOR;
      21.  
      22. IF flag = TRUE THEN
      23. OutString := TempString;
      24. ELSE
      25. // OutString := "";
      26. END_IF;

       

      Expand Post
      • ADC Community_02 (Automationdirect.com)

        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

        Selected as Best
      • kewakl (Customer)

        Again, Thank you very much.

      • kewakl (Customer)

        Interesting coincidence...

        I have been working on a single-character find/replace routine for another guy here.

        Then you drop ST that includes REPLACE()

  • Kevin Roman (Customer)

    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.