# Problem with DialogInput and store variable

Writing:

fct[input_, output_, type_] := Module[{}, DialogInput[DialogNotebook[
{TextCell[input],
InputField[Dynamic[output], type],
DefaultButton[DialogReturn[output]]},
Background -> Green,
Magnification -> 1.5]]
];

list = ConstantArray[0, 10];

For[i = 1, i <= 10, i++,

Clear[msg]; fct["Insert number:", msg, Number];

list = ReplacePart[list, i -> msg]

]


through a mask it is possible to populate list.

However, if the first request is entered 1, at the second request I would not like the box to be empty, but contain 1, which can only be changed if desired.

Is it possible to do this by maintaining the structure proposed above?

Thank you!

• What if the first is 2? Should the second be empty? Or should it always be initialized to the previous value? – Kuba Mar 1 '18 at 19:47
• @Kuba: thanks for your patience! Yes, I would like there to be memory of the last value entered. Thank you so much! – TeM Mar 1 '18 at 20:18

This is how I'd do it:

fct[input_, init_, type_: Number] := DialogInput[
{var = init}
, Pane[
Column[
{ TextCell[input]
, InputField[Dynamic[var], type, SystemBoxID -> "number"]
, DefaultButton[DialogReturn[var]]
}
]
, ImageMargins -> 5
]
, Background -> Green
, Magnification -> 1.5
, NotebookDynamicExpression :> (Refresh[
FrontEndMoveCursorToInputField[EvaluationNotebook[], "number"]
, None
])
];


and now just:

list = Rest@NestList[
fct["Insert number:", #] &, 0, 10
]


More about MoveCursorToInputField in 152536 and 1454 but it is not relevant here.

• Thanks so much! One last thing, if I can: is it possible to save the value entered in a variable? For example, above in "msg". Thanks again! – TeM Mar 2 '18 at 9:56
• @TeM yes, you can do it your way but since you are replacing parts of list later anyway I just skipped this part and you generate list directly. – Kuba Mar 2 '18 at 10:00