using uCalcSoftware; var uc = new uCalc(); static void CustomIIf(uCalc.Callback cb) { bool condition = cb.ArgBool(1); var truePart = cb.ArgExpr(2); var falsePart = cb.ArgExpr(3); if (condition) { cb.Return(truePart.Evaluate()); } else { cb.Return(falsePart.Evaluate()); } } uc.DefineFunction("MyIIf(condition As Bool, ByExpr thenExpr, ByExpr elseExpr)", CustomIIf); // The 'else' branch contains a division by zero, but it should NOT be evaluated // because the condition (1 < 2) is true. var result = uc.Eval("MyIIf(1 < 2, 100, 1/0)"); Console.Write("Result 1: "); Console.WriteLine(result); // Now test the false branch. The 'then' branch with the error is skipped. result = uc.Eval("MyIIf(1 > 2, 1/0, 200)"); Console.Write("Result 2: "); Console.WriteLine(result);