Variável global e local na macro

Da wiki ArcoWiki
Ir para: navegação, pesquisa

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