views:

52

answers:

1

I am working on VS C# on the following code, which converts an user input math expression and computes it.

        MSScriptControl.ScriptControl sc = new MSScriptControl.ScriptControl();
        sc.Language = "VBScript";

        sc.ExecuteStatement(
            "function pi\n"
            + "pi = 3.14159265\n"
            + "end function");

        sc.ExecuteStatement(
            "function e\n"
            + "e = exp(1)\n"
            + "end function");

        expression = textBox1.Text.ToString();
        expression = expression.Replace("x", i.ToString());
        object y = sc.Eval(expression);

        string k = y.ToString();
        double result = double.Parse(k);

While this outputs onto the console with the correct result, I want to use the values to make a graph of the function user inputs and it's not doing it correctly.

Thank you for your help.

+5  A: 

Use a cast :

double result = (double)y;

Or if it doesn't work, try Convert.ToDouble :

double result = Convert.ToDouble(y);
Thomas Levesque