项目添加对 Microsoft.JScript
Microsoft.Vsa 的引用
代码
protected
void
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());
}
public object 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());
}
public object EvalExpress( string sExpression)
{
Microsoft.JScript.Vsa.VsaEngine ve = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
return Microsoft.JScript.Eval.JScriptEvaluate(sExpression, ve);
}