About the Calculation Editor

You can use the Calculation Editor in the Data Exchanger component to create or edit a calculation action. The editor consists of a text area for entering expressions and an operation bar for selecting and inserting parameters, operators, and functions. You access the Calculation Editor by clicking the button on the toolbar.

The Calculation Editor is similar to the Calculator component. For more information about the Calculator component, see Calculator Component.

The differences between the Calculation Editor in the Data Exchanger component and the Calculator component are as follows:

  • The Calculator component allows one statement per line without semicolons. A Data Exchanger calculation can contain multiple statements, but there must be a semicolon after each statement (except the last).

  • The Calculation Editor allows full Java statement syntax, including expressions as subscripts of arrays, and calling methods on parameters (which are type com.engineous.sdk.vars.Variable). This includes Java auto increment/decrement operators (++ and --) and the operation assign operators, such as i+=1.

  • The Calculator component supports array operations such as outArr=2×inArr to multiply each element in inArr and assign it to the associated position in outArr. The Calculation Editor does not support this operation.

  • Arrays are resized in the Calculator component only by assigning a whole array to the parameter or by assigning a whole array to an element beyond the current end of the array. In the Calculation Editor, an array parameter can be resized either by calling the array.setDimSize(size) method or with the resize(array,size) function.

  • The Calculator component requires single quotation marks around parameters containing spaces. The Calculation Editor renames parameters by replacing all punctuation and spaces with underscores. If you select a parameter, such as strength/weight ratio and click the button, the Data Exchanger component inserts the calculation as strength_weight_ratio.

Note: The same Calculation Editor is used for If and While statements and to enter expressions for row and column numbers in the Vector and Table formats. The only difference is that a calculation must contain assignment statements, whereas the other uses must be an expression that does not assign the value to a parameter.

The following are examples of calculations:

  • Increment the value of an integer parameter i. The following are equivalent:
    i++
    i+=1
    i=i+1
    
  • Set an element of array parameter array to a complex expression. The subscript is one less than the integer parameter i.
    array[i-1] = array[i] * cos(x)
  • Change the size of array outArray to be twice as large as the array inArray:

    resize(outArray, size(inArray) *2)