Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

VAR_STAT in METHOD of a PROGRAM

massimo
2020-08-26
2020-08-26
  • massimo - 2020-08-26

    Situation:
    - I have a program with many methods.
    - Some methods use fb/vars that need memory between one call and next call

    If a won't declare it in program body, how i can proceed? I found VAR_STAT and test it, with success.

    Help says that static variables retain their value when the application exits the function block

    It is true also for PROGRAMS?

    Thank's in advance

    Massimo

     
  • aliazzz

    aliazzz - 2020-08-26

    Indeed, VAR_STAT can be seen as if a variable is declared in the body of the parent POU (so an FB or a PROGRAM). In techspeak: the declaration of the VAR_STAT variables are placed on the stack of the parent POU, instead of on the stack of the METHOD itself.

    To sum it up: 'regular' variables in the METHOD declaration lose their contents after ending the METHOD, while VAR_STAT variables never lose their content after ending the METHOD.

    I Hope this anwsers your question.

     
    πŸ‘
    1

    Last edit: aliazzz 2020-08-26

Log in to post a comment.