Object PmExpr (Evaluation tool of JavaScript expression)
Description:
Object allows evaluation of JavaScript expression entered as String.
Properties and methods:
SetVar() | Adds one variable into the object |
SetExpr() | Sets an expression in the form of a text string |
Eval() | Evaluation of entered expression |
Note:
The expression can be added into the object by
SetExpr. This expression can contain variable names. These variables can be added into the object by the
SetVar method. The
Eval method then evaluates the expression (including variables) and returns the result.
Evaluation of expression by means of the
PmExpr object is useful for example if the expression is read as a text string (e.g. from the file, from the communication …) meaning that the final form ofthe expression is previously unknown.
For example the application for general data evaluation needs to have the data processing expressions to be located in a configuration text file.
Examples of expression evaluation by means of the PmExpr object:
Evaluation of simple expression "a+b":
JavaScriptVBScriptSelect and copy to clipboard
var val;
var oExpr = Pm.CreatePmExpr();
oExpr.SetExpr("a+b");
oExpr.SetVar("a", 3);
oExpr.SetVar("b", 2.5);
val = oExpr.Eval();
// In the val variable there will be the 5.5 value
Dim val, oExpr
Set oExpr = Pm.CreatePmExpr()
oExpr.SetExpr "a+b"
oExpr.SetVar "a", 3
oExpr.SetVar "b", 2.5
val = oExpr.Eval()
' In the val variable there will be the 5.5 value
Evaluation of expression using the PmaData object:
JavaScriptVBScriptSelect and copy to clipboard
var val;
var oExpr = Pm.CreatePmExpr();
oExpr.SetExpr("10 * oDat.Item('Temperature').Value");
oExpr.SetVar("oDat", pMe.Pm("/Boiler1/Data"));
val = oExpr.Eval();
// In the val variable there will be the value 10times greater than the value of temperature in the PmaData object
Dim val, oExpr
Set oExpr = Pm.CreatePmExpr()
oExpr.SetExpr "10 * oDat.Item('Temperature').Value"
oExpr.SetVar "oDat", pMe.Pm("/Boiler1/Data")
val = oExpr.Eval()
' In the val variable there will be the value 10times greater than the value of temperature in the PmaData object