1
$\begingroup$

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!

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

This is how I'd do it:

fct[input_, init_, type_: Number] := DialogInput[
  {var = init}
, Pane[
    Column[
      { TextCell[input]
      , InputField[Dynamic[var], type, System`BoxID -> "number"]
      , DefaultButton[DialogReturn[var]]
      }
    ]
  , ImageMargins -> 5
  ]
, Background -> Green
, Magnification -> 1.5
, NotebookDynamicExpression :> (Refresh[
    FrontEnd`MoveCursorToInputField[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.

$\endgroup$
  • $\begingroup$ 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! $\endgroup$ – TeM Mar 2 '18 at 9:56
  • 1
    $\begingroup$ @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. $\endgroup$ – Kuba Mar 2 '18 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.