使用Microsoft脚本控制,以评估“如果'表达式(通过C#) [英] Use Microsoft Scripting Control to evaluate 'If' expressions (via c#)
问题描述
我有一个使用Microsoft脚本控制,以评估一些表达式一些C#代码:
I have some c# code that uses the Microsoft Scripting Control to evaluate some expressions:
using MSScriptControl; // references msscript.ocx
ScriptControlClass sc = new ScriptControlClass();
sc.Language = "VBScript";
sc.AllowUI = true;
try
{
Console.WriteLine(sc.Eval(txtEx.Text).ToString());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
(txtEx是一个简单的文本字段)
(txtEx is a simple text field)
数值表达式:6 + 4,COS(34),ABS(-99),圆(1.234,2)等都是精细
Numerical expressions: "6+4", "cos(34)", "abs(-99)", "round(1.234, 2)" etc. are fine
布尔表达式:真的还是假的,1 = 2都很好。
Boolean expressions: "true or false", "1=2" are fine
但我怎么能评估如果简单?我曾尝试:如果(真实,2,3),IIF(真实,2,3),如果(真),那么2其他3和如果(真),那么2其他3 ENDIF
But how can I evaluate a simple 'if'? I have tried "if(true, 2, 3)", "iif(true, 2, 3)", "if (true) then 2 else 3" and "if (true) then 2 else 3 endif"
任何人可以帮我评估简单的条件表达式?任何帮助非常感谢!
Can anybody please help me to evaluate simple conditional expressions? Any help much appreciated!
RH
推荐答案
尝试包装你的IF -expression在一个函数
Try wrapping your IF-expression in a function
Function test
if (true) then
return true
else
return false
end if
End function
添加功能控制,然后使用运行
Add the function to the control and then use Run
Result = ScriptControl.Run("Test")
(上面的代码没有进行测试,而是沿着这样的东西应该工作)
(the code above is not tested, but something along that way should work)
看看这个链接更多的一些信息。
Check out this link for some more info
http://support.microsoft.com/kb/184740
这篇关于使用Microsoft脚本控制,以评估“如果'表达式(通过C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!