I have written code, with the help of stackoverflow of course, and I want to make it user friendly so that other people in my lab can use it. I'm playing with DialogCreate and similar functions. I want to do something like this so far:

   "General" ->
      Row[{TextCell["Project Name:"], InputField[Dynamic[Project]]}],
      Row[{TextCell["Number of Wells:"], InputField[Dynamic[num]], 
        Button["Set", DialogReturn[num]]}]}],
   "Row Selection" ->
      Row[TextCell["Well " <> ToString[i] <> ":"], 
      FileNameSetter[Dynamic[Evaluate[Symbol["w" <> ToString[i]]]], 
     "Open"]], {i, 1, num}]}]}, ControlPlacement -> Left]

I want to dynamically create more rows based on the input of "Number of Wells" within the same dialogbox but in a different tab. Is anything like this possible or some sort of alternative?

  • $\begingroup$ Code doesn't run as posted. Looks like you may need to define "Project". Hard to tell without the example running. $\endgroup$
    – Jagra
    Commented Aug 29, 2012 at 20:07
  • $\begingroup$ Check the answer below, it worked well. :) $\endgroup$
    – tquarton
    Commented Aug 30, 2012 at 0:06

1 Answer 1

   {"General" -> 
     Column[{Row[{"Project Name:", InputField[Dynamic[project]]}],
        Row[{"Number Of Wells:", InputField[Dynamic[num]], 
        Button["Set", DialogReturn[num]]}]}], 
   "Row Selection" -> 
      Table[Row[{"Well " <> ToString[i] <> ":", 
         FileNameSetter[Dynamic[Evaluate[Symbol["w" <> ToString[i]]]],
            "Open"]}], {i, 1, num}]]}, 
   ControlPlacement -> Left]]

enter image description here

Update: There are two problems in the original code:

First, regarding the use of Do, unless an explicit Return is used, the value returned by Do is Null. Please see the docs on Do and the tutorial Loops and control structures. For example

 t = 2; Do[t = 1 + k t, {k, 1, 2}]

does the calculation to change the value of t but does not return anything. You need to explicitly call the new value of t to see the effect of what happened inside Do:

t = 2; Do[t = 1 + k t, {k, 1, 2}];t
(* which gives the result: 7 *)

So, to get your code working with Do, you need to do something like:

"Row Selection" -> 
  Dynamic@Column[tt = {};
  Do[AppendTo[tt, Row[{"Well " <> ToString[i] <> ":",
   FileNameSetter[Dynamic[Evaluate[Symbol["w" <> ToString[i]]]], 
   {i, 1, num}]; tt]

which, of course, is not as clean as the alternative with Table[...].

Second, regarding why Dynamic[Column[ ...]] is needed please see the tutorial Introduction to Dynamic, in particular, the section Where Should Dynamic Be Placed in an Expression?

By the way, @ is short form of Prefix, and f@x is an alternative syntax for f[x], that is, Dynamic@Column[.....] is the same as Dynamic[Column[...]].

  • $\begingroup$ Perfect! Thanks so much kguler. $\endgroup$
    – tquarton
    Commented Aug 29, 2012 at 23:01
  • $\begingroup$ So can you explain what adding the @ does that makes this work? I'd like to learn how you knew how to do that. $\endgroup$
    – tquarton
    Commented Aug 29, 2012 at 23:15
  • $\begingroup$ @tquarton, thank you for the accept. Please see the update with links to useful material. $\endgroup$
    – kglr
    Commented Aug 30, 2012 at 8:31

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.