3
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ +1 I'm puzzled that someone marked this as a favorite question without upvoting it. $\endgroup$ – DavidC Sep 19 '12 at 18:22
  • $\begingroup$ Sometimes I'll mark my own questions as favorite so that it keep the question along with all my other favorites. But I am not allowed outvote my own post. So this could be why. $\endgroup$ – Michael McCain Jan 4 '16 at 0:22
6
$\begingroup$

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"]]}];
$\endgroup$
  • $\begingroup$ Thanks a lot, this is it!! And also for your great idea adding a popupmenu. Fantastic. $\endgroup$ – Harald Sep 19 '12 at 15:14
  • $\begingroup$ 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? $\endgroup$ – Harald Sep 19 '12 at 17:33
  • $\begingroup$ I changed it so it works now $\endgroup$ – David Slater Sep 19 '12 at 18:10
  • $\begingroup$ Thanks a lot, apart from being more or less a beginner with Mathematica, I would have never found a solution for that... $\endgroup$ – Harald Sep 19 '12 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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