How Do I Re-use Expressions Within Another Expression? (Magic xpa 4.x)
One of the nice things about the expression list is that one expression can be re-used in many places within a task. Commonly the same expression is used in many calculations, especially expressions used to reset variables, such as 0, 'TRUE'LOG, 'FALSE'LOG, or DATE().
You can also create a simple user function that returns the expression, and use that in other expressions.
Alternatively, you can also use one expression within another expression, by using the ExpCalc() function. ExpCalc() allows you to enter a complex function once, and reuse it in another expression.
For instance, in this example, three fields are totalled in expression #1, and displayed onscreen as a subtotal. The subtotal is then used inside expression #2, and the fourth field added on to it.
-
Enter ExpCalc(
-
Enter the number of the expression you want calculated, using the EXP literal. In this example, we are looking at expression #1, so we enter '1'EXP.
-
Add the final paren: )
The EXP literal is what allows Magic xpa to keep track of the expression if it moves. For instance, if we added another expression in front of expression #1, then the '1'EXP would automatically change to '2'EXP.
The Online and Rich Client Samples projects (program EX01 and REX01)