宏中的全局和局部变量

来自ArcoWiki
Slia讨论 | 贡献2018年6月7日 (四) 08:07的版本 (创建页面,内容为“The Declaration of A VariableVariables declaration in a Macro can be GLOBAL or LOCAL. == Global Declaration == The <code>GLOBAL</code> modifier in the […”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航搜索

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