mandag den 20. juli 2009

How to programmatically (X++) calculate a mathematical expression i Dynamics AX

This code snippet shows how to calculate a mathematical expression and get the result in X++ code (the shown code is made as a job):


static void calc(Args _args)
{
XppCompiler x;
// In str s we write the expression that we want to evaluate
Str s = "1+2*(8+4)*cos(25)";
Str result;
;
x = new XppCompiler();
if (x.compileExpr(s))
{
result = x.execute();
}
else
{
result = "Error in formula";
}
info(result);
}

Ingen kommentarer:

Send en kommentar