Re: adding scripting to a Winforms application by Jako
Jako
Thu Oct 20 19:20:38 CDT 2005
"torque" <torque@discussions.microsoft.com> wrote in message
news:08AC9627-3930-405C-9A03-03379579F12C@microsoft.com...
>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.
>
>
> --
> Thanks in Advance
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....