Ask a Question related to Macromedia ColdFusion, Design and Development.

  1. #1

    Default Avoiding Evaluate

    I'm starting with a formula, which is a string, in a variable. For example,
    calcFormula = (a + b) / c. I replace parts of the string with numeric values
    so that I end up with calcFormula's value being something like this: (2 + 4) / 2

    I need to calculate the value of calcFormula now. Is there another way to do
    this besides the below?
    calcValue = Evaluate("#calcFormula#")


    perezle Guest

  2. Similar Questions and Discussions

    1. Evaluate my site...
      I posted this in DHTML so I didn't get a million responses. Check out http://www.viswiz.biz/simacor/simacor.html I am not looking for design...
    2. evaluate string
      Hi I hve a list mylist= I am inserting the values dynamically in the string format in the list and the list becomes mylist=] or mylist=] now...
    3. Cookie & evaluate
      Hi All, Heres my problem... This snippet of code: <cfif isDefined('#evaluate('COOKIE.poll' &amp; FORM.pollID)#')> is causing this error: Variable...
    4. PreserveSingleQuotes and Evaluate
      Hi all. I've run into a bit of a problem with part of an application. I have users inputting , what can be, multiple animal (Species) names and...
    5. Please evaluate my Project
      For my MSc in Multimedia project I am developing a 3D surgery simulation centre for othtopaedic surgeons and physiotherapists. I have developed a...
  3. #2

    Default Re: Avoiding Evaluate

    Normally you would just set the a, b, and c values, then use:
    <cfset calcValue = (a + b) / c>


    OldCFer Guest

  4. #3

    Default Re: Avoiding Evaluate

    I don't know the structure of the formula until the page loads, so I don't know
    if I have an a or b or what beforehand. Replacing all parts of the formula at
    the end would be trickier. I'd prefer to replace incrementally. Any other
    ideas?

    perezle Guest

  5. #4

    Default Re: Avoiding Evaluate

    > I don't know the structure of the formula until the page loads, so I don't know
    > if I have an a or b or what beforehand. Replacing all parts of the formula at
    > the end would be trickier. I'd prefer to replace incrementally. Any other
    > ideas?
    I'm usually the first person to say "don't use evaluate() if at all
    possible", but this is case, it's the correct tool for the job (IMO).
    --

    Adam
    Adam Cameron Guest

  6. #5

    Default Re: Avoiding Evaluate

    As Adam said,

    This is an instance when evaluate is appropriate. Your alternative is to
    write an equation parser -- which can be fun but the boss might not understand.

    Be sure to wrap the result in HTMLEditFormat or use some other means to guard
    against cross-site scripting attacks.

    MikerRoo Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139