Tell me more ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I would like to execute the following code, in which if the condition is true it should execute two instructions instead of one. When I run the code the instructions are executed, but no result is shown.

Ac = Input[];
Print[Ac];

If[Ac == 1,

   instruction1

   var := instruction2;

  ];

the instruction1 should show a grid in which you can modify the value of 4 parameters, and the instruction2 should use the value of these dyanmic variables in order to compute the result.

Instruciton1 is:

Grid[
    {{"", "Theta", "d", "Alpha", "a"},
     {"Link1",
      InputField[Dynamic[Subscript[th, 1]], FieldSize -> 3], 
      InputField[Dynamic[Subscript[d, 1]], FieldSize -> 1], 
      InputField[Dynamic[Subscript[alpha, 1]], FieldSize -> 4], 
      InputField[Dynamic[Subscript[x, 1]], FieldSize -> 1]
      }}, Frame -> Darker[Gray, .6],
    Alignment -> {{Left, {Center}}}
    ]

Isntruction2 is:

linea[Dynamic[Subscript[th, 1]], Dynamic[Subscript[d, 1]], 
    Dynamic[Subscript[alpha, 1]], Dynamic[Subscript[x, 1]]]

Instruction1 and Instruction2 give the following result, cf image.! image

I haven't found any documentation about it. Is it possible to use the If function in Mathematica or should I use another one?

share|improve this question
1  
Note that Grid does not show a grid. It is a grid (it represents a grid). The system just happens to show the result of your last calculation, if you don't follow it with a ; character. To instruct the system to print an expression, use Print. – Szabolcs Jan 17 at 17:00
When using compound expressions, it is the output of the last term that is returned. But, a; b; is interpreted as CompoundExpresion[a, b, Null], and Null returns nothing. Use a; b, instead, which drops the Null from CompoundExpresion. – rcollyer Jan 17 at 17:08
@rcollyer : same result without the ; after the second instruction. – narutov6 Jan 17 at 17:30
@Szabolcs : I think that the problem is related to the Grid function with Dynamic variables. Is it possible to show a normal grid in an If without using the Print funciton? Anyway with if[cond,Print[Grid[...]]; Print[Instruction2]]; it works! Thank you – narutov6 Jan 17 at 18:01
3  
Is your If statement essentially verbatim what you're running? If so, you're missing a semi-colon after instruction1. – rcollyer Jan 17 at 18:19
show 2 more comments

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.