Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In the following code how can I keep the DynamicModule from computing values if the input values are not all filled? If I don't specify default values it will show the code used to compute the values instead of blank values.


backingAgreementValue[w_, \[Sigma]_, 
  a_] := \[Sigma] /Sqrt[2 \[Pi]] Exp[ -(w - a)^2/(2 \[Sigma]^2)] + 
  w CDF[NormalDistribution[0, 1], (w - a)/\[Sigma]]

DynamicModule[{w = 40, \[Sigma] = 600, a = 0, n = 100, horseCut = 0.5,
   backingValue, expectation, backerValue, horseValue, 
  horseExpectationPercentage, values}, 
     Transpose[{{Style["Mean", Blue], 
        Style["Standard Deviation", Blue], Style["Threshold", Blue], 
        Style["N", Blue], Style["Player Cut", Blue], 
        Style["Backing Agreement Value", Orange], 
        Style["Expectation", Orange], Style["Player Value", Orange], 
        Style["Player Expectation Percentage", Orange], 
        Style["Backer Value", Darker[Magenta]]}, {InputField[
         Dynamic[w], Number], InputField[Dynamic[\[Sigma]], Number], 
        InputField[Dynamic[a], Number], 
        InputField[Dynamic[n], Number], 
        InputField[Dynamic[horseCut], Number],
         Style[backingValue = 
           backingAgreementValue[expectation, \[Sigma] Sqrt[n], a] // 
            N, If[backingValue >= 0, Darker[Green], Red]]],
         Style[expectation = w n // N, 
          If[expectation >= 0, Darker[Green], Red]]],
         Style[horseValue = horseCut  backingValue // N, 
          If[horseValue >= 0, Darker[Green], Red]]],
         Style[horseExpectationPercentage = 
           horseCut backingValue/expectation // N, 
          If[horseExpectationPercentage >= 0.5, Darker[Green], Red]]],
         Style[backerValue = (expectation -  
              backingValue + (1 - horseCut) backingValue) // N, 
          If[backerValue >= 0, Darker[Green], Red]]]}}], 
     Alignment -> Left], ImageMargins -> 10], 
   DefaultOptions -> {InputField -> {ContinuousAction -> True, 
       FieldSize -> {{5, 30}, {1, Infinity}}}}]], 
 SaveDefinitions -> True]
share|improve this question
SaveDefinitions is not an option for DynamicModule – Mike Honeychurch Aug 18 '13 at 11:22
Thanks but how does this help with my initial question? – dabd Aug 18 '13 at 11:26
@MikeHoneychurch In Version 9 SaveDefinitions is an option of DynamicModule. SaveDefinitions /. Options[DynamicModule, SaveDefinitions] gives False. Sure, it is not documented, but a lot is not documented ... – Rolf Mertig Aug 18 '13 at 12:53
@RolfMertig ok. I have V8 on this computer and work with 8 most of the time – Mike Honeychurch Aug 18 '13 at 12:56
@MikeHoneychurch I never use M8 anymore. M9 is really better for DynamicModule, CDF's and all that jazz. – Rolf Mertig Aug 18 '13 at 12:59
up vote 1 down vote accepted

Wrap a test around the visible code. If the test passes then display the calculation otherwise display a e.g. spacer:

If[NumberQ[\[Sigma]]&&NumberQ[n]& ...etc,
  backingValue = 
   backingAgreementValue[expectation, \[Sigma] Sqrt[n], a] // N, 
  If[backingValue >= 0, Darker[Green], Red]]],
share|improve this answer

Your Answer


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.