自定义公式编辑
项目添加对 Microsoft.JScript
Microsoft.Vsa 的引用
代码
protectedvoid Cal_Click(object sender, EventArgs e)
{
string g = TextBox1.Text;
g=g.Replace("{a}", a.Text);
g=g.Replace("{b}", b.Text);
g=g.Replace("{c}", c.Text);
Response.Write("公式"+g);
object r = EvalExpress(g);
Response.Write("计算结果:"+r.ToString());
}
publicobject EvalExpress(string sExpression)
{
Microsoft.JScript.Vsa.VsaEngine ve = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
return Microsoft.JScript.Eval.JScriptEvaluate(sExpression, ve);
}
{
string g = TextBox1.Text;
g=g.Replace("{a}", a.Text);
g=g.Replace("{b}", b.Text);
g=g.Replace("{c}", c.Text);
Response.Write("公式"+g);
object r = EvalExpress(g);
Response.Write("计算结果:"+r.ToString());
}
publicobject EvalExpress(string sExpression)
{
Microsoft.JScript.Vsa.VsaEngine ve = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
return Microsoft.JScript.Eval.JScriptEvaluate(sExpression, ve);
}


浙公网安备 33010602011771号