Unique Solutions to Universal Problems

Home USPExpress Getting started
Microsoft Certified Partner

News

August 27, 2018

Support of USPExpress .NET CFE products is discontinued.

July 23, 2018

Support of USPExpress .NET CFE products will be discontinued in August 2018.

July 9, 2018

USPExpress .NET Pro SL support 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

  1. Declare and create USP.Express.Pro.Parser object:

    using USP.Express.Pro;
    ...
    Parser m_cParser = new Parser();

  2. 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");

  3. 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.
     
  4. 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;

  5. 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 

  1. Declare and create USPExpress.USPExpression object: 

    USPExpress.USPExpression cParser;
    cParser = new USPExpress.USPExpression();

  2. 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"};

  3. Parse the expression: 

    try
    {
    cParser.Parse(sExpression, sVariables);
    }
    catch(USPExpress.ParseException ex)
    {
    // ...
    }

    ParseException is raised, if the expression is not parsed successfully.
     
  4. 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");

  5. 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.