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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
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.
Last edit: aliazzz 2020-08-26