This form is used to create, edit or modify Expression items. The user can enter the Expressions name under "Calculation of" and write the code which implements an algorithm in the editor under "with Expression" label. Below the code editor is a list box where all exported symbols (or parameters) are listed after code evaluation. The user can change their order or set default values.
Lets explain the way this form is used with an example. Say we want to write
an algorithm that computes the average value of three numbers. First we enter
the name of Expression under "Calculation of" as "Average"
as the picture shows. Second we have to write the code that implements the
"average value of three numbers". We can see this code in the picture
under "with expression". This code has three statements. The first
adds the contents of three variables n1, n2, n3 and puts the result in variable
r1. The second divides the contents of r1 over 3 and puts its result in variable
r2. The third defines the return value of the whole code. Apparently this
code computes the average value of three numbers. If we press button
the code is evaluated and the exported symbols list box at the bottom fills in
with n1, n2, n3. It appears that we have to enter values to these variables to
compute the average value of three numbers. How CalcIt knows that? CalcIt
considers a variable of known value only when the user assigns to it a value
using the assignment operator (:=
). If
Expression code tries to access the value of a variable before a value is
assigned to it then this variable it is considered of unknown value and becomes
an external variable. This happens with the first statement of
the example code. To compute the sum of n1, n2, n3 we need to know their values
but where in this code, especially before this statement, these values are
defined? So the user will have to enter their values in a Calculation bounded to
this expression. By contrary, variables r1 and r2 take a value with the assignment
operator and their values are known before any read access to them inside
the scope of this code. So become internal
variables and are used for intermediate results.
CalcIt lists external variables in the order of their appearance in the code. With the same order they appear to the user in a Calculation item form. If the user wants a different order he/she can use drag & drop in the external variables list box to change it.
In Calculation's form, where the user enters values for external variables, some times is desirable to set a default value for a variable because most of the times this is the case. For example consider an exported variable that takes a tax percentage. This is, say, 18% in the most cases and very rarely something else. In such a case we can define a default value of 18 for this variable. Under external variables list box there is an edit box. We select the variable we want and in this box we enter its default value.
Note that we can write there whatever is valid when entering values for Calculation parameters. Can be a whole expression. This is just copied when a new Calculation for this Expression is created or reset to default. The text typed as the default value for an external variable is not evaluated in any way at this point. It is simply stored as it is entered.
By default a numeric value is expected from an Expression item. Any other type returned produces an error. In cases we want a more complex format of the output or simply an alphanumeric value, we must uncheck the "Numeric Result" check box.
NOTES:
See also Main Screen, Code Editors