Christian, thanks for your help. It worked. I'm going to share my
result with the community:
ScriptEngine engine = ScriptRuntime.Create().GetEngine("py");
ScriptScope scope = engine.CreateScope();
scope.Execute(@"
def calculate(operand1, operand2, operator):
if operator == '+': return operand1 + operand2
if operator == '-': return operand1 - operand2
if operator == '*': return operand1 * operand2
if operator == '/': return operand1 / operand2
return 0
");
int operand1 = 0;
int.TryParse(textBox1.Text, out operand1);
int operand2 = 0;
int.TryParse(textBox2.Text, out operand2);
object func = scope.GetVariable("calculate");
string theOperand = comboBox1.SelectedItem.ToString(); // +, -, *, /
var parameters = new ArrayList();
parameters.Add(operand1);
parameters.Add(operand2);
parameters.Add(theOperand);
object result = engine.Operations.Call(func, parameters.ToArray());
textBox3.Text = result.ToString();
_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com