0
$\begingroup$

I have a bit of a weird question: I have a program which I transformed from an old Mathcad Program written by someone else which is a hot mess. It uses a bunch of constants in lists as inputs in various places. This isn't really important for the question, but I want to underline that it is unavoidable in this context (without some major rewrite which I am unwilling to do at this point!).

At the moment I have a few lists of these values which I wrote manually like so:

var1={val1,val2,val3,...,valn}
var2={val1,val2,val3,...,valn}
var3={val1,val2,val3,...,valn}

All values are numbers and some of them need changing and as it is now it is difficult to change because for example I need to change val3 in var2 and I need to be careful all the time. My question is: is there a way to create some sort of graphical table with placeholders and a comment next to each placeholder for extra info, where I input the values val1,val2,val3 etc, such that they all belong to list var1? Then I modify for example val1 and the list is updated accordingly. Also, in the program I should be able to use the list as usual.

I know about DynamicModule but I have no clue if I can use these with a graphical placeholder of sorts to create lists of constants that can then be used later in the program.

$\endgroup$

1 Answer 1

1
$\begingroup$

When may misuse Input for your purpose.

Assume that your initial values are given in var and the corresponding info in info (note both vectors must have the same length), the following function returns the corrected values:

getVar[var_, info_] := Module[{out},
  Input[
   Manipulate[
    , {{tab, Transpose[{var, info}], "Variables"}, 
     Grid[Table[
        With[{i = i, j = j}, 
         InputField[
          Dynamic[tab[[i, j]], (tab[[i, j]] = #; 
             out = tab[[All, 1]];) &], ImageSize -> Tiny]], {i, 
         3}, {j, 2}]] &}]
   , "Click O.K. when done"]; out]

Here is a small teste example:

var = {1, 2, 3};
info = {"aaa", "bbb", "ccc"}
getVar[var, info]

enter image description here

We may no change the values:

enter image description here

After clicking "O.K." we get the result:

{111, 222, 333}
$\endgroup$
3
  • $\begingroup$ thank you for this answer! when you say "we get the answer" does that mean that var is updated to the new values? $\endgroup$
    – lucian
    Commented Apr 18, 2021 at 12:59
  • $\begingroup$ The return value of the function is the updated value. To update var you would write: var= getVar[var,info] $\endgroup$ Commented Apr 18, 2021 at 13:06
  • $\begingroup$ aha! this is great! I think I can create a workflow with this solution! thank you for this! $\endgroup$
    – lucian
    Commented Apr 18, 2021 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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