0
$\begingroup$

I currently have the following code:

Panel[Column[{{"Purchase Price", 
InputField[Dynamic[purchaseprice], Number, 
 FieldHint -> "Purchase Price", 
 ImageMargins -> 10]}, {"Equity Capital", 
InputField[Dynamic[EK], Number, FieldHint -> "Equity capital", 
 ImageMargins -> 10]}, {"Mortgage rate in %", 
InputField[Dynamic[mortgagerate], Number, 
 FieldHint -> "Mortgage Rate in %", 
 ImageMargins -> 10]}, {"Supplementary Costs per annum", 
InputField[Dynamic[supplymentary], Number, 
 FieldHint -> "Supplementary costs per annum", 
 ImageMargins -> 10]}, {"Payback Period", 
InputField[Dynamic[paybackperiod], Number, 
 FieldHint -> "Payback Period", 
 ImageMargins -> 10]}, {"Gross Income per annum", 
InputField[Dynamic[grossincome], Number, 
 FieldHint -> "Gross Income per annum", 
 ImageMargins -> 10]}, {"Calculatory mortgage rate", 
InputField[Dynamic[calcrate], Number, 
 FieldHint -> "Calculatory mortgage rate", ImageMargins -> 10]}, 
Dynamic@If[
 grossincome*0.33 > (purchaseprice - EK)*mortgagerate/100 + 
   supplymentary + 
   Max[{((purchaseprice - EK) - 0.66*purchaseprice)/paybackperiod,
      0}], TextCell[
  "Congratulation you are qualified for a mortgage", "Subtitle"], 
 Dynamic[Text["You only have "] Text[
    Round[((purchaseprice - EK)*mortgagerate/100 + supplymentary +
           Max[{((purchaseprice - EK) - 0.66*purchaseprice)/
             paybackperiod, 0}])/purchaseprice*100] Text[
      "% instead of 33%"]]]]}, 
Background -> 
Dynamic@If[
 grossincome*0.33 > (purchaseprice - EK)*mortgagerate/100 + 
   supplymentary + 
   Max[{((purchaseprice - EK) - 0.66*purchaseprice)/paybackperiod,
      0}], Green, Red]]]

My problem is, that I need to format my text output in the end. Normally I would use TextCell to do that, but given that I do have a dynamic input, which needs to be transformed to a string, this is not an option. Anyone got a workaround for that?

Edit: I need to change the FontSize and FontColor of my numerical text here:

Text[
    Round[((purchaseprice - EK)*mortgagerate/100 + supplymentary +
           Max[{((purchaseprice - EK) - 0.66*purchaseprice)/
             paybackperiod, 0}])/purchaseprice*100]
$\endgroup$
  • 2
    $\begingroup$ Which text output? How do you want it formatted? Can you make a minimal example? Currently the problem bit might be drowned by irrelevant code. $\endgroup$ – MarcoB Jun 26 '18 at 16:01
  • $\begingroup$ Yes sure, sorry. I need to change the FontSize and FontColor of my numerical text $\endgroup$ – julsto Jun 26 '18 at 16:03
  • 1
    $\begingroup$ Lookup Style $\endgroup$ – halirutan Jun 26 '18 at 16:12
  • $\begingroup$ Already did but wont work $\endgroup$ – julsto Jun 26 '18 at 16:26
  • $\begingroup$ Have you tried ToString to make your calculation text? Should be able to wrap the whole calculation in ToString and then apply your text style code as needed. $\endgroup$ – kickert Jun 26 '18 at 17:54
2
$\begingroup$

Maybe this code will give you ideas on how to fix yours.

DynamicModule[{purchaseprice, EK, mortgagerate, supplymentary, paybackperiod, grossincome, calcrate},
   purchaseprice = 100000.;
   EK = 200000.;
   mortgagerate = 3.;
   supplymentary = 0.;
   paybackperiod = 30;
   grossincome = 100000.;
   calcrate = 1.;
   Panel[
     Column[
       {Grid[
          {{"Purchase Price", 
            InputField[Dynamic[purchaseprice], Number, ImageMargins -> 10]},
           {"Equity Capital", 
            InputField[Dynamic[EK], Number, ImageMargins -> 10]},
          {"Mortgage rate in %", 
           InputField[Dynamic[mortgagerate], Number, ImageMargins -> 10]}, 
          {"Supplementary Costs per annum", 
           InputField[Dynamic[supplymentary], Number, ImageMargins -> 10]}, 
          {"Payback Period", 
           InputField[Dynamic[paybackperiod], Number, ImageMargins -> 10]}, 
           {"Gross Income per annum", 
            InputField[Dynamic[grossincome], Number, ImageMargins -> 10]},
           {"Calculatory mortgage rate", 
            InputField[Dynamic[calcrate], Number, ImageMargins -> 10]}},
          Alignment -> {Right, Left}], 
        Dynamic @ 
          If[
            grossincome*0.33 > 
              (purchaseprice - EK) mortgagerate/100 + supplymentary + 
              Max[{((purchaseprice - EK) - 0.66*purchaseprice)/paybackperiod, 0}],
             Style[
               "Congratulations, you have qualified for a mortgage",
               "Text",
               Background -> Green],
             Style[
               Row[
                 "You only have ", 
                 Round[
                  ((purchaseprice - EK) mortgagerate/100 + 
                   supplymentary +
                   Max[{((purchaseprice - EK) - 0.66 purchaseprice)/paybackperiod, 0}])/purchaseprice 100], 
                 "% instead of 33%"],
               "Text",
               Background -> Red]]}]]]

panel

$\endgroup$

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