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.

Is it possible to change TextCells in the following code in that way, that the TextCell "profile starts at x =" changes to "profile starts at y =" and at the same time the TextCell "measurement starts at y =" changes to "measurements starts at x =" when the input of the user is "y" in the TextCell "direction of the profile (x / y)"?

Moreover I don't know why "TextAlignment -> Right" has no effect...

Here is the code:

code = ""; ffn = ""; lfn = ""; add = 0; direction = "x"; rs = ""; \
length = ""; startmeasurement = ""; distance = "";
DialogInput[
  Grid[{{Grid[{{TextCell["Code (004p):", FontSize -> 16, 
         TextAlignment -> Right], 
        InputField[Dynamic[code], String, 
         FieldSize -> {10, 1}]}}]}, {Grid[{{TextCell[
         "first filenumber:", FontSize -> 16, TextAlignment -> Right],
         InputField[Dynamic[ffn], Number, FieldSize -> {10, 1}],

        TextCell["last filenumber:", FontSize -> 16, 
         TextAlignment -> Right], 
        InputField[Dynamic[lfn], Number, FieldSize -> {10, 1}],

        TextCell["addition to filenumber", FontSize -> 16, 
         TextAlignment -> Right], 
        InputField[Dynamic[add], Number, FieldSize -> {10, 1}]},

       {TextCell["direction of the profile (x / y):", FontSize -> 16, 
         TextAlignment -> Right], 
        InputField[Dynamic[direction], String, FieldSize -> {2, 1}],

        TextCell["profile starts at x =", FontSize -> 16, 
         TextAlignment -> Right], 
        InputField[Dynamic[rs], Number, FieldSize -> {10, 1}],

        TextCell["length of the profile [m]:", FontSize -> 16, 
         TextAlignment -> Right], 
        InputField[Dynamic[length], Number, FieldSize -> {10, 1}]},

       {TextCell["measurement starts at y =", FontSize -> 16, 
         TextAlignment -> Right], 
        InputField[Dynamic[startmeasurement], Number, 
         FieldSize -> {10, 1}],

        TextCell["Distance between profiles (+0.5 / -0.5):", 
         FontSize -> 16, TextAlignment -> Right], 
        InputField[Dynamic[distance], Number, FieldSize -> {10, 1}]}},
       Frame -> All],


     DefaultButton[DialogReturn[og]]}}], 
  NotebookEventActions -> {"ReturnKeyDown" :> 
     FrontEndExecute[NotebookWrite[InputNotebook[], "\n"]]}];

Thanks a lot for your help.

share|improve this question
    
+1 I'm puzzled that someone marked this as a favorite question without upvoting it. –  David Carraher Sep 19 '12 at 18:22
add comment

1 Answer

up vote 6 down vote accepted

Sure. Just replace

TextCell["profile starts at x =", FontSize -> 16, 
     TextAlignment -> Right]

With

 Dynamic[TextCell["profile starts at" <> ToString[direction] <> " =", FontSize -> 16, TextAlignment -> Right]]

and

TextCell["measurement starts at y =", FontSize -> 16,  TextAlignment -> Right]

by

Dynamic[TextCell["measurement starts at " <> ToString[direction]<> " =", FontSize -> 16, TextAlignment -> Right]

Since you only want direction to be "x" or "y" you may want to use a different control object such as a popupmenu:

  code = ""; ffn = ""; lfn = ""; add = 0; directions = {"x","y"}; rs = ""; \
  length = ""; startmeasurement = ""; distance = ""; choice=1;
  DialogInput[
  Grid[{{Grid[{{TextCell["Code (004p):", FontSize -> 16, 
     TextAlignment -> Right], 
    InputField[Dynamic[code], String, 
     FieldSize -> {10, 1}]}}]}, {Grid[{{TextCell[
     "first filenumber:", FontSize -> 16, TextAlignment -> Right],
     InputField[Dynamic[ffn], Number, FieldSize -> {10, 1}],

    TextCell["last filenumber:", FontSize -> 16, 
     TextAlignment -> Right], 
    InputField[Dynamic[lfn], Number, FieldSize -> {10, 1}],

    TextCell["addition to filenumber", FontSize -> 16, 
     TextAlignment -> Right], 
    InputField[Dynamic[add], Number, FieldSize -> {10, 1}]},

   {TextCell["direction of the profile (x / y):", FontSize -> 16, 
     TextAlignment -> Right], 
   PopupMenu[Dynamic[choice], {1-> "x", 2-> "y"}],

    Dynamic[TextCell["profile starts at "<>directions[[choice]]<> " =", FontSize -> 16, 
     TextAlignment -> Right]], 
    InputField[Dynamic[rs], Number, FieldSize -> {10, 1}],

    TextCell["length of the profile [m]:", FontSize -> 16, 
     TextAlignment -> Right], 
    InputField[Dynamic[length], Number, FieldSize -> {10, 1}]},

   {Dynamic[TextCell["measurement starts at "<>directions[[Mod[choice+1,2,1]]]<> " =", FontSize -> 16, 
     TextAlignment -> Right]], 
    InputField[Dynamic[startmeasurement], Number, 
     FieldSize -> {10, 1}],

    TextCell["Distance between profiles (+0.5 / -0.5):", 
     FontSize -> 16, TextAlignment -> Right], 
    InputField[Dynamic[distance], Number, FieldSize -> {10, 1}]}},
   Frame -> All],


 DefaultButton[DialogReturn[og]]}}], 
 NotebookEventActions -> {"ReturnKeyDown" :> 
 FrontEndExecute[NotebookWrite[InputNotebook[], "\n"]]}];
share|improve this answer
    
Thanks a lot, this is it!! And also for your great idea adding a popupmenu. Fantastic. –  Harald Sep 19 '12 at 15:14
    
Hi, one TextCell is not exactly working correct. The code is: {Dynamic[TextCell["measurement starts at " <> direction <> " =", FontSize -> 16, TextAlignment -> Right]]. But it should show just the opposite direction chosen in the other TextCell, not the same... How can this be managed? –  Harald Sep 19 '12 at 17:33
    
I changed it so it works now –  David Slater Sep 19 '12 at 18:10
    
Thanks a lot, apart from being more or less a beginner with Mathematica, I would have never found a solution for that... –  Harald Sep 19 '12 at 18:37
add comment

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.