Page 1 of 1

Syntax for Global Variables

Posted: Tue Apr 16, 2013 2:07 pm
by tomok
Question for you guys about global variables (I've never used them):

The documentation states you declare them (which I think means create them) by the command; StringGlobalVariable('VariableName'); and they should be available to all other processes in the same chore. The problem I encounter is that I get a syntax error in all the processes in the chore, except the one where the variable is created, whenever I try to edit those processese, saying the variable has not been declared. Do I have to use the StringGlobalVariable('VariableName'); command in all the processes? If so, does that create the global variable all over again? Does anyone have any examples of using global variables? Thanks in advance.

Re: Syntax for Global Variables

Posted: Tue Apr 16, 2013 2:27 pm
by Duncan P
You have to declare it both to set it and to use it. A global variable is shared between all processes in the same call that declare it.

One thing I use global variables for is to declare and set constants across the system. There is a single process SetConstants that declares and sets all the constants. Then each process that wants one of these constants runs SetConstants and declares the constants it wants to use. SetConstants has a first line that checks to see if it has been run - by checking one of the constants that it sets.

Re: Syntax for Global Variables

Posted: Tue Apr 16, 2013 2:34 pm
by ioscat
Global variables can be declared in one process and be made available to any subsequent processes called by the ExecuteProcess( ) function. These sub-processes must use the same global variable declaration statements (described below) to access the global variables.
http://pic.dhe.ibm.com/infocenter/ctm1/ ... 8069C.html

Re: Syntax for Global Variables

Posted: Tue Apr 16, 2013 2:38 pm
by tomok
Duncan P wrote:You have to declare it both to set it and to use it. A global variable is shared between all processes in the same call that declare it.

One thing I use global variables for is to declare and set constants across the system. There is a single process SetConstants that declares and sets all the constants. Then each process that wants one of these constants runs SetConstants and declares the constants it wants to use. SetConstants has a first line that checks to see if it has been run - by checking one of the constants that it sets.
Thanks. it would be nice if the IBM documentation stated that you have to use the StringGlobalVariable('VariableName') declaration in every process, that the first time actually CREATES the variable, and all the subsequent calls just access whatever is currently in the variable.

Re: Syntax for Global Variables

Posted: Tue Apr 16, 2013 2:39 pm
by tomok
ioscat wrote:
Global variables can be declared in one process and be made available to any subsequent processes called by the ExecuteProcess( ) function. These sub-processes must use the same global variable declaration statements (described below) to access the global variables.
http://pic.dhe.ibm.com/infocenter/ctm1/ ... 8069C.html
Thanks for the link but it doesn't answer my question, which is why I posted in the first place. Duncan covered it.