Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Code doesn't run as posted. Looks like you may need to define "Project". Hard to tell without the example running. – Jagra Aug 29 '12 at 20:07
Check the answer below, it worked well. :) – tquarton Aug 30 '12 at 0:06
up vote 12 down vote accepted

Does the following work as needed?

   {"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[...]].

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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