title: Use Microsoft Scripting Control to evaluate 'If' expressions (via c#)
body: <p>I have some c# code that uses the Microsoft Scripting Control to evaluate some expressions:</p>
  
  <pre><code>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);
  }
  </code></pre>
  
  <p>(txtEx is a simple text field)</p>
  
  <p>Numerical expressions: "6+4", "cos(34)", "abs(-99)", "round(1.234, 2)" etc. are fine</p>
  
  <p>Boolean expressions: "true or false", "1=2" are fine</p>
  
  <p>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"</p>
  
  <p>Can anybody please help me to evaluate simple conditional expressions? Any help much appreciated!</p>
  
  <p>RH</p>