Message Boards Message Boards

0
|
4577 Views
|
1 Reply
|
1 Total Likes
View groups...
Share
Share this post:

Reload result of a simple operation using PopupMenu[]

Posted 9 years ago

Your problem occurs because the series of If statements are only evaluated once, when the dialog window is initially made. Here, I replace them with a single Switch statement inside a Dynamic, so it's evaluated every time something changes.

CreateWindow[
  DialogNotebook[{TextCell[
     "Enter the type of operation to be performed:"], 
    DynamicSetting[
     PopupMenu[
      Dynamic[list], {"Sum", "Substraction", "Multiplication", 
       "Division", "Powers", "Roots"}]], 
    TextCell["Enter the first operand: "], 
    DynamicSetting[InputField[Dynamic[num1], Expression]], 
    TextCell["Enter the second operand: "], 
    DynamicSetting[InputField[Dynamic[num2], Expression]],
    (*Realiza la operación de acuerdop al campo de selección*)
    TextCell["Its outcome is: "], Dynamic[Switch[list,
      "Sum", num1 + num2,
      "Substraction", num1 - num2,
      "Multiplication", num1*num2,
      "Division", num1/num2,
      "Powers", num1^num2,
      "Roots", num1^(1/num2)]], 
    ChoiceButtons[{DialogReturn[Dynamic[result]]}]}, 
   WindowTitle -> "Basic Operation"], WindowSize -> All];
POSTED BY: Jesse Friedman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract