Method: AddCalculationChannel for Channels <Data>
- Updated2024-09-12
- 2 minute(s) read
Internal Data > Methods > Method: AddCalculationChannel for Channels <Data>
Method: AddCalculationChannel for Channels <Data>
Generates, in the script interface for internal data, a new calculation channel in the current channel group with a simple single-line formula.
Set oCalculationChannel = Object.AddCalculationChannel(Name, Formula, [DestUnit], [DestIndex])
| Object | Channels <Data> Object with this method |
| Name | String Specifies the name of the result channel. |
| Formula | String Specifies the formula. In a formula, you can use channels of the associated channel group, constants, numbers, and variables that reference values and channels. The channel names must not contain spaces, various special characters, or reserved DIAdem or VBS names, for example, Time, because otherwise DIAdem will use the reserved DIAdem or VBS name instead of the formula. Use CH to access these channels, for example, CH("Time"). If DIAdem cannot calculate the formula of an existing formula channel because, for example, an input channel is missing, DIAdem deletes all values and the unit of the formula channel when you update the values of this channel. If the functionality of the formula channel is not sufficient for your task, use the AddCalculationChannelRef method to use a calculation from the Calculation Manager. |
| [DestUnit] | String Specifies the unit symbol of the calculation channel. If you specify a unit, DIAdem sets the QuantityBased for CalculationChannel <Data> to True and converts the unit to the specified unit. Refer to the Help page Calculating Quantity-Based and Non-Quantity-Based in DIAdem for the conditions and rules for quantity-based calculations. If you specify the "Default" value, DIAdem uses the matching default unit of the active unit set for the result channel. If you specify an empty string as unit symbol, DIAdem specifies the unit symbol. |
| [DestIndex] | LongInteger Specifies the index of the new calculation channel within the collection of existing channels. If you do not specify the index, DIAdem appends the calculation channel to the collection of existing channels in the channel group. |
| oCalculationChannel | CalculationChannel <Data> Returned object |
The following example generates a calculation channel from a formula with the unit "m/s".
| VBScript | Python |
Dim oMyCalculationChn Set oMyCalculationChn = Data.Root.ChannelGroups(1).Channels.AddCalculationChannel("Result", "=Speed * 2", "m/s", 1)