Formula Syntax of the Calculator
- Updated2024-09-12
- 3 minute(s) read
Calculator > Formula Syntax of the Calculator
Formula Syntax of the Calculator
The syntax that you use for formulas in the Calculator corresponds to the VBS syntax.
-
Specify the formula as follows: Result = Expression.
-
You can use all VBS functions and all DIAdem functions in the formulas of the Calculator.
-
Use the equals sign as the assignment sign, for example, MyVar = 3. The calculation result is on the left side of the assignment.
-
Enclose text in quotation marks, for example, strMyVar = "Text".
-
Use the variable CH to access channels. For each value in the input channels, DIAdem calculates results according to the formula you enter in the Calculator. If the data channels in the calculation are different lengths, the result channel is the same length as the shortest data channel. Channel operations in the Calculator are faster then if you run a loop in a VBS script over all the rows in a channel. In channel calculations you must always specify a target channel.
For example, you can use one command to convert all the characters of a text channel into uppercase letters:
VBScript Python Ch("[1]/MyUpperChn") = UCase(Ch("[1]/TxtChn")) You also can use a text channel as a parameter for the VBS function InputBox and save the results of this request in a new channel:
VBScript Python Ch("[1]/MyResult") = InputBox(Ch("[1]/TxtChn")) - In a calculation DIAdem does not save temporary variables and does not create temporary channels.
For example, assume you have a channel MyChn with the values 10, 20, and 30 and execute the following calculation in the VBS syntax:VBScript Python CH("MyChn")=CH("MyChn") - Data.GetChannel("MyChn").Values(1) The result in the channel MyChn is 0, 20, and 30. The calculation of the first channel value returns the value 0, which DIAdem uses for the calculation of the subsequent channel values.
-
NoValue behaves like Zero. In VBS syntax, the result of a calculation with NoValues is always a NoValue. Refer to Defining NoValues for more information about these rules. In some cases, for example when you eliminate outliers, you use the function CTNV.
- Use the ValEqual command instead of the equals sign if you want to check whether two real numbers are equal. DIAdem uses only the significant digits of a number in the ValEqual command.
-
Use the Calculate command to use the Calculator in scripts. You must enclose the formula you want to calculate in quotation marks. If a formula already includes single quotation marks, you must replace these quotation marks with double quotation marks.
VBScript Python Call Calculate("Ch(""[1]/ResultVBS"") = 2 * Ch(""[1]/Input"")")
![]() | Note Refer to the procedures Executing Channel Calculations in the Calculator and Executing Channel Calculations in a Script for information on the formula syntax of the Calculator. |
