News
Version 2.404 of Dentist Assistance 2 (DA2) is released.
Version 2.384 of Dentist Assistance 2 (DA2) is released.
Support of USPExpress .NET CFE products is discontinued.
USPExpress: getting started
You should take the following two steps when applying USPExpress to an expression:
- Parse the expression.
Parsing results in producing an expression tree. Once the tree is built, the expression can be evaluated many times against various variable values.
- Evaluate the expression.
Since the expression tree is already built, evaluation of the expression is performed with maximum possible speed - no additional overhead is involved.
Below is a step-by-step guide to USPExpress usage (in C# syntax). You may also refer to the Sample projects and the Class Reference document, which are enclosed with the installation package.
USPExpress .NET Pro
- Declare and create USP.Express.Pro.Parser object:
using USP.Express.Pro;
...
Parser m_cParser = new Parser();
|
- Specify variables which you intend to use in your expression.
Four variables named X1, X2, X3, X4 are specified in the example below:
m_cParser.Variables.Add(new Variable("x1", typeof(Double)));
m_cParser.Variables.Add(new Variable("x2", typeof(DateTime)));
m_cParser.Variables.Add(new Variable("x3", typeof(String)));
m_cParser.Variables.Add(new Variable("x4", typeof(Boolean)));
|
Optionally, you may add aliases to your variables. Each variable can have one or more aliases:
m_cParser.Variables.Item(2).Aliases.Add("OrderDate");
|
- Parse the expression and obtain an expression tree:
ExpressionTree m_oExpressionTree = null;
try
{
m_oExpressionTree = m_cParser.Parse("Your Expression");
}
catch(Exceptions.ParseException ex)
{
...
}
catch(Exception ex)
{
...
}
|
ParseException is raised, if the expression is not parsed successfully.
- Assign actual values to the variables that you specified on step 2:
object[] m_aValues = new object[4];
m_aValues[0] = 1.0;
m_aValues[1] = DateTime.Now;
m_aValues[2] = "test string";
m_aValues[3] = true;
|
- Evaluate the expression:
string sResult;
try
{
sResult = m_oExpressionTree.Evaluate(m_aValues).ToString();
}
catch(Exceptions.EvaluateException ex)
{
MessageBox.Show(ex.Message);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
|
EvaluateException is raised, if the expression is not evaluated successfully.
USPExpress Math Parser .NET
- Declare and create USPExpress.USPExpression object:
USPExpress.USPExpression cParser;
cParser = new USPExpress.USPExpression();
|
- Specify variables, which you intend to use in your expression. Three variables named X1, X2, X3 are specified in the example below:
string[] sVariables = new string[]{"X1", "X2", "X3"};
|
- Parse the expression:
try
{
cParser.Parse(sExpression, sVariables);
}
catch(USPExpress.ParseException ex)
{
// ...
}
|
ParseException is raised, if the expression is not parsed successfully.
- Assign actual values to the variables that you specified on step 2:
double[] dValues = new double[]{35, 2, 3};
|
Or, if you want to evaluate an expression containing DateTime variables:
object[] oValues = new object[3];
oValues[0]= 35;
oValues[1] = 2;
oValues[2] = Convert.ToDateTime("12.12.2003");
|
- Calculate:
double dExpValue;
try
{
dExpValue = cParser.Evaluate(dValues);
}
catch(UXPExpress.EvaluateException ex)
{
// ...
}
|
Or, if you want to evaluate an expression containing DateTime variables:
string sExpValue;
try
{
sExpValue = cParser.EvaluateEx(oValues);
}
catch(UXPExpress.EvaluateException ex)
{
// ...
}
|
EvaluateException is raised, if the expression is not evaluated successfully.