I want to request user input of an expression of f(x) from a dialog and then use ToExpression
on the input.
Questions:
- When I execute the code below, I got r before I click the button. So that I get r before I actually enter the expression. Is it because I'm using Dynamic[input]?
- How to execute the last line after I hit the button?
x = Table[i, {i, 20}];
input = "";
CreateDialog[
Grid[
{{"f(x)=", InputField[Dynamic[input], String]},
{"", "Input expression f(x)"},
{"", DefaultButton["OK", DialogReturn[ret = input]]}},
Spacings -> {0.5, Automatic},
Alignment -> Center
],
Modal -> True,
WindowTitle -> "Input information"];
r = ToExpression[ret, TraditionalForm];