adding scripting to a Winforms application

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have been tasked to develop an application that allows the user to define
an equation and them execute over a large data range. The powers that be have
decided it will use the IVsaEngine to accomlish this. I am looking for any or
all examples and/or books and/or articles that will help me to implement this.
 
torque said:
I have been tasked to develop an application that allows the user to define
an equation and them execute over a large data range. The powers that be
have
decided it will use the IVsaEngine to accomlish this. I am looking for any
or
all examples and/or books and/or articles that will help me to implement
this.


You can do this by creating an instance of a Microsoft.JScript.Vsa.VsaEngine
by calling the static Microsoft.JScript.Vsa.VsaEngine.CreateEngine()
function. Use this instance as the second argument when calling
Microsoft.JScript.Eval.JScriptEvaluate. This first argument for this
function can be a string with the equation you want to evaluate, e.g.

using Microsoft.JScript;
using Microsoft.JScript.Vsa;

public class Stuff
{
public static double GetValue(string equation)
{
VsaEngine vsaEngine = VsaEngine.CreateEngine();

double dRet = Convert.ToDouble(Eval.JScriptEvaluate(equation,
vsaEngine));

vsaEngine.Close();

return dRet;
}
}

and you can call this by GetValue("(2 * 10) + 5") and it should return 25.
Now you just have to build in some error handling...

Hope this is what you were looking for....
 
Back
Top