Global Variable / Local Variable crossing

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
Rudi
Posts: 666
Joined: Mon Feb 10, 2014 4:59 am
Has thanked: 493 times
Been thanked: 187 times

Global Variable / Local Variable crossing

Post 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
;-)

Kenrix2
Flowcode v5 User
Posts: 211
Joined: Tue Feb 19, 2013 9:51 pm
Has thanked: 72 times
Been thanked: 177 times
Contact:

Re: Global Variable / Local Variable crossing

Post 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.
Attachments
pass a local variable.fcfx
(4.56 KiB) Downloaded 260 times

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Global Variable / Local Variable crossing

Post 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
call.JPG (14.12 KiB) Viewed 4157 times
"glob1" and "glob2" are examples of 1 in the list above. ".loc1" is example of 2.
example.JPG
example.JPG (13.02 KiB) Viewed 4157 times
"glob4" and "glob5" are examples of 3.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

Post Reply