Page 1 of 1
Global Variable / Local Variable crossing
Posted: Fri Mar 28, 2014 7:25 pm
by Rudi
Hi
only a question:
is it possible example
in main program to catch a local variable from a macro like this
flowchart
main...calc....calc2
in main
mainglobal=calc.local + calc2.local
and / or
is it possible in a macro to catch a localvariable from main / macro like
calclocal = main.local + calc2.local
Thank you!
Rudi
Re: Global Variable / Local Variable crossing
Posted: Sat Mar 29, 2014 12:12 am
by Kenrix2
Using global variables would make it very simple. Using local variables is possible, but I don't understand the advantage. Attached is a program using only local variables. I am still learning V6 so maybe an experienced V6 programmer can come up with a better way.
Re: Global Variable / Local Variable crossing
Posted: Sat Mar 29, 2014 12:35 am
by kersing
Rudi wrote:in main program to catch a local variable from a macro like this
flowchart
main...calc....calc2
in main
mainglobal=calc.local + calc2.local
No, this is not possible. After you leave a macro the local variables are destroyed and the values are lost.
Rudi wrote:is it possible in a macro to catch a localvariable from main / macro like
calclocal = main.local + calc2.local
If you need access to a variable from multiple macros (main and another macro):
1) If you do not need to modify the variable, use it as an argument to the macro call. That way you know it is being used in the macro.
2) If only one variable needs to be modified, return the value from the macro and assign it in the calling macro.
3) If you need to modify multiple variables, use global variables. It is good programming practice to avoid using global variables and assigning them values in macros as much as possible as it is hard to trace where and when global variables are modified.
Examples of the points above:
- call.JPG (14.12 KiB) Viewed 4227 times
"glob1" and "glob2" are examples of 1 in the list above. ".loc1" is example of 2.
- example.JPG (13.02 KiB) Viewed 4227 times
"glob4" and "glob5" are examples of 3.