This web site requires Java Script.
You must enable Java Script on
your browser to navigate this site.















How to perform math calculations

Any object in ModCom which is capable of executing a function, can also perform a mathematical calculation on a Variable or Screen Object. This is accomplished by selecting the "Math Conversion" function and typing in the mathematical equation. This equation is similar to a common algebraic expression used in other programming languages and can contain the four basic arithmetic operators (+, -, /, *), complex Math functions (Sine, Cosine, Square Root, etc.), constants with or without a decimal point, and any of the other Variables and Screen Objects available in the project.

Spacing and Parentheses:

A mathematical expression may contain spaces throughout the text string in order to make it more easier to read. These spaces are removed before the calculation is performed. When evaluating, an equation is processed from left to right unless parentheses are used to control the exact order of evaluation. It is recommended that parentheses be used anytime there are multiple operators in the expression. This makes it easier to read as well as assuring the correct grouping of operators and their operands.

Using Variables:

One or more variables can be included within the mathematical expression. A variable is a name of a Screen Object enclosed in curly braces like this: {DataWindow1} When evaluating an expression containing a variable such as mentioned above, the variable name will be substituted with the current numerical value of DataWindow1. A variable can be a Screen Object located elsewhere in ModCom, or it can be the identical Screen Object which is being operated on by the "Math Conversion" function. If the later, the current value of the Screen Object will be used to calculate the new value of itself.

Data Format of a Screen Object:

When using a Screen Object as a variable in a mathematical expression, it must hold a numerical value. A Text Window containing alpha characters, for instance, should not be used as a variable in an expression. Note however that an Event Timer is the one exception. Even though an Event Timer may contain colons which are alpha characters, the value is automatically converted over to seconds whenever it is used as a variable. Whether in a mathematical expression, or anywhere else that ModCom accepts variables. When a Data Window or any of the instrument gauges are used as a variable in an expression, its value will always be retrieved as the decimal equivalent regardless of the output type (Dec, Hex, Bin) chosen to be displayed on the screen.

Decimal Point Positioning:

Any numerical constants in a mathematical expression (or the value of a variable for that matter) can contain digits to the right of the decimal point. These digits will be used in the calculation however, when the results from a "Math Conversion" function is sent to its Screen Object, the old value of that Screen Object will determine the number of digits to the right of the decimal point which will be displayed. Any extra digits returned from the "Math Conversion" function will be rounded out. You can force a Text Window to display any number of digits to the right of the decimal point by setting its default message to 0.0000 for instance. The decimal point position of a Data Window can be controlled with its offset value as with any normal polling operations.

Data Limitations and Overflow:

All mathematical calculations use a 32-bit signed integer for the results. Therefore, at anytime the results exceed the range of -2,147,483,647 to 2,147,483,647 an overflow will occur and the word "Overflow" will be sent to the Screen Object that is the recipient of the Math Conversion.