最新消息:ww12345678 的部落格重装上线,希望大家继续支持。

How to Calculate Values from a Formula, written in Algebraic Expression, in MS Dynamics Ax 2012

Uncategorized William 1194浏览 0评论

ExpressionEvaluate

方法1:


static void CalculateExpression(Args _args)
{
    str expr = "(((1+2)*6)/5)";
    ;

    info(num2str(ProdMathEvaluator::evaluate(expr),0,2,1,3));
}

方法2:


static void calculateExpression(Args _args)
{
    XppCompiler comp;

    str expr;

    expr = "(((1+2)*6)/5)";

    comp = new XppCompiler();

    info(strFmt('%1',comp.compileExpr(expr)));//this validates the expression

    info(strFmt('%1',comp.execute(expr)));//this returns the result.
}

方法3:


static void JobEvalBufDemo(Args _args)
{
     ExecutePermission perm;
     str strCodeToExecute = "(((1+2)*6)/5)";
     str strResult;
     ;
     perm = new ExecutePermission();
     if (perm != null)
     {
          // Grants permission to execute the EvalBuf function.
          // EvalBuf runs under code access security.
          perm.assert();
          print "Next will execute the string of code.";
          pause; // Click Yes when asked to continue.

          strResult = EvalBuf(strCodeToExecute);
          // Close the code access permission scope.
          CodeAccessPermission::revertAssert();
     }
     print "strResult is: [", strResult ,"]";
     pause;
     //
     // Expected: "strResult is: [3.6]".
}

转载请注明:ww12345678 的部落格 | AX Helper » How to Calculate Values from a Formula, written in Algebraic Expression, in MS Dynamics Ax 2012

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址