Using a VBscript in to calculate a variable
There are a number of instances where a simple formula may not be enough to do the conversion that you require. Typical examples are if you require:
- some sort of memory of previous samples/data/variables
- combinational logic (e.g. if/else, case/select, switch etc)
- complex or non-standard mathematical operations
In these instances, you have to use the scripting language option - this is far more flexible in terms of what you are able to do compared with a simple formula, however this flexibility comes at the price of some additional complexity and speed of execution.
IMPORTANT: the scripting language that is used in the RT analysis software is exactly the same as is implemented in Microsoft products (eg Word and Excel). Please refer to the internet or Microsoft for documentation on how to use the scripting language, the commands available and the required syntax. Only the particulars of our implementation are given here.
Here is a simple example of a script:
There are a couple of important sections:
The script must contain a function called "output" which returns a value
- All the variables referenced must be in the correct format of VAR_xxxx - note that the variable index must be specified as 4 digits, eg VAR_0001 cannot be shortened to VAR_1
- Note that unlike a formula, you cannot include 'u' or 'x' to reference the variable the script is associated with
- All the variables in the script are "variants", you cannot set the type to singles/doubles etc
- The code is case insensitive
- You can include constants, just as you can with formulas
IMPORTANT: Scripts can be slow to run as they are interpreted at runtime - if you find that this is not practical for your requirements then please consider using an external DLL
There is one final point about the code above - variables that are defined outside (before) the main output function are persistent (or static) between calls of the output function - this can be very useful. This property allows the code the remember previous values or states and allow time dependant functions like differentiation and filtering etc.