Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm trying to create an interface with Mathematica. However, I need some instructions concerning the code below. This is about 10% of what I have in mind, but first I need to know how can I create ns InputFields after ns is defined by the user making a choice from the popup menu.

ns : number of station
sf : sound frequency
ws : width of window

CreateWindow[
  DialogNotebook[
  {
    TextCell["Number of Stations: "],
    PopupMenu[Dynamic[ns], Range[2, 8]],

    TextCell["Sound Frequency (kHz): "],
    InputField[Dynamic[sf], String, FieldSize -> 7],

    TextCell["Window Size (ms): "],
    InputField[Dynamic[ws], String, FieldSize -> 7],

    TextCell["Calculation Start relative to the Window (ms): "],
    InputField[Dynamic[cs], String, FieldSize -> 7],

    ChoiceButtons[{DialogReturn[{retNS = ns, retSF = sf, retWS = ws, retCS = cs}]}]
  },
  WindowTitle -> "Fluvial Acoustic Tomography Configuration"]];
share|improve this question

1 Answer 1

Here is one solution:-

CreateWindow[DialogNotebook[{TextCell["Number of Stations: "],
    PopupMenu[Dynamic[ns, (
        ns = #;
        (* set default values *)
        Function[n, (x[n] = 0)] /@ Range[ns];
        col = Column[InputField[Dynamic[x[#]]] & /@ Range[ns]]) &],
     Range[2, 8]], TextCell["Sound Frequency (kHz): "],
    Dynamic[col], TextCell["Window Size (ms): "], 
    InputField[Dynamic[ws], String, FieldSize -> 7], 
    TextCell["Calculation Start relative to the Window (ms): "], 
    InputField[Dynamic[cs], String, FieldSize -> 7],
    ChoiceButtons[{DialogReturn[
       {retNS = ns, retSF = sf, retWS = ws, retCS = cs}]}]}, 
   WindowTitle -> "Fluvial Acoustic Tomography Configuration"],
  WindowSize -> All];

enter image description here

share|improve this answer
    
Thanks for the comprehensive answer. I was just wondering if there is any way to have at least two empty slots as a default mode (min [ns] = 2) and if input ns is larger than 2, more slots are added. –  K-1 Mar 31 '13 at 13:40
    
@K-1 - You could modify the initialisation to: ns = 2; col = Column[InputField[Dynamic[x[#]]] & /@ Range[ns]] –  Chris Degnen Mar 31 '13 at 14:24
    
@ Chris Degnen: I've already tried that, those slots don't appear unless you click on the popup menu regardless of the initial value of "ns" –  K-1 Apr 1 '13 at 1:49
    
@K-1 - I didn't encounter the problem you mention, but I have updated my answer anyway. It works fine, at least on Mathematica 9. –  Chris Degnen Apr 1 '13 at 11:03

Your Answer

 
discard

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.