Difference between revisions of "Global And Local Variable In Macro"

From ArcoWiki
Jump to: navigation, search
(Created page with "The Declaration of A VariableVariables declaration in a Macro can be GLOBAL or LOCAL. == Global Declaration == The <code>GLOBAL</code> modifier in the [[variable]...")
 
 
(One intermediate revision by one other user not shown)
Line 31: Line 31:
  
 
<code>CALL/M(SUM_TWO_NUMBERS),100,200</code>
 
<code>CALL/M(SUM_TWO_NUMBERS),100,200</code>
 +
 +
 +
[[it:Variabile globale e locale nella macro]]
 +
[[zh-cn:宏中的全局和局部变量]]
 +
[[pt:Variável global e local na macro]]
 +
[[de:Globale und lokale Variable im Makro]]
 +
[[es:Variable global y local en macro]]
 +
[[en:Global And Local Variable In Macro]]

Latest revision as of 07:50, 7 June 2018

The Declaration of A VariableVariables declaration in a Macro can be GLOBAL or LOCAL.

Global Declaration

The GLOBAL modifier in the variable declaration makes the variable created in the macro accessible to the main Program.
This is used when the result of a macro shall be used in the main program.
The Following example will show that the result of the macro will be in the DB Viewer even if the variable has not been declared explicitly in ARCO.

$$ Example of a MACRO with GLOBAL Result
M(SUM_TWO_NUMBERS)=MACRO/NUMBER1,NUMBER2

DECL/GLOBAL,DOUBLE, RESULT
RESULT=ASSIGN/NUMBER1+NUMBER2

ENDMAC

CALL/M(SUM_TWO_NUMBERS),100,200


Local Declaration

The LOCAL modifier in the variable declaration makes the variable created in the macro NOT accessible to the main Program. This is useful when a support variable shall be used in the macro but it is not interesting for the main program.
The Following example will show that the result of the macro will be in the DB Viewer but not the temporary variable.

$$ Example of a MACRO with GLOBAL Result and Temporary Variable Locally declared
M(AVERAGE_3_NUMBER)=MACRO/NUMBER1,NUMBER2,NUMBER3

DECL/LOCAL,DOUBLE, SUM
DECL/GLOBAL,DOUBLE, RESULT
SUM=ASSIGN/NUMBER1+NUMBER2+NUMBER3
RESULT=ASSIGN/SUM/3

ENDMAC

CALL/M(SUM_TWO_NUMBERS),100,200