IIF function question

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default IIF function question

    I'm studying for my ColdFusionMX exam using Ben Forta's study guide. There is
    quite a bit of errata in the book, including code that simply doesn't work.
    It's very frustrating. I thought maybe if I posted some of these code samples
    here I could get a correct answer. It's not in the errata, so if anyone could
    shed some light on this one I would appreciate it: What will be the output of
    the following code?: <CFOUTPUT>#IIF(1 is 1,'1;2;3',''Hello'')#</CFOUTPUT>
    According to the book the answer to this is 3. After reading Forta's
    description of the IIF function I chose the right answer to this question in
    the book. Not having used IIF at all I then decided to have a play and started
    off by using this code. It doesn't work. Forta says, 'ColdFusion evaluates
    multiple expressions from left to right and will return the rightmost
    expression. Therefore, using scripting syntax, we could place a number of
    expressions inside of the IIf() function and return the last one evaluated.' He
    also says that multiple expressions are separated by semicolons. So based on
    that I figured the correct answer to the above question was 3. Unfortunately,
    the code doesn't actually work, so now I'm confused. My question is... Is the
    problem in the syntax of the expression 1 or is Forta's description of IIF
    incorrect? If anyone can come up with the correct syntax for this code,
    something that evaluates the 3 expressions that make up expression 1 and
    returns 3 as the result I would love to see it. I've tried some variations but
    haven't found the correct one yet. I don't want to go into the exam with false
    information.

    xor3 Guest

  2. Similar Questions and Discussions

    1. Function Question
      Hi! Is there a considerable degredidation in speed if I where to include an ASP page into every other ASP page that would contain all the...
    2. Simple AS function question
      Why will this not work home_btn.onRollOver = setInterval(delayAction,2000,home); function delayAction (framename:String) var name:String =...
    3. PHP function question
      When writing a function that takes in a variable number of parameters and processing it using func_get_args or a similar technique, I'm assuming...
    4. utf8_decode function question
      Hi folks, I read in a security note that something known as a cross-site scripting attacker can use utf8 encoding and that you could decode data to...
    5. Question: ConnectToDatabase function
      Thanks! I wasn't sure if the Try code would continue or not if an exception was "caught". Now I know it doesn't. "Marina" <mzlatkina@hotmail.com>...
  3. #2

    Default Re: IIF function question

    Try to Use DE
    <CFOUTPUT>#IIF(1 is 1,DE('1;2;3'),DE('Hello'))#</CFOUTPUT>
    Der Nickname Guest

  4. #3

    Default Re: IIF function question

    Der Nickname using your code it will output '1;2;3' , according to Ben's book
    it should only return '3'.

    I have been trying to get it to work on CF 6.1 and haven't had any luck.
    Fernis, I agree, I thought what was in the TRUE/FALSE expressions was just
    evaluated/output, didn't think it would accept multiple expressions.

    The book didn't come with a CD containing the working examples did it?

    Might want to try to get a response from [email]Ben@forta.com[/email] before you exam to
    clear this issue up. Would be interested to see what you find out.

    Zoe

    zoeski80 Guest

  5. #4

    Default Re: IIF function question

    Hi Fernis, and thanks! I think you are right, I have been reading up on IIf in
    a few other references, including the Macromedia CF reference pdf and there is
    no mention of evaluating multiple statements. Since posting this I have also
    tried other code from the book which uses multiple expressions in one
    expression and they too come up with errors. So thanks for confirming this with
    your findings... I have hit a couple snags in the book like this and it slows
    me down significantly as I keep trying to get it to work. It's a pretty
    significant error to say that the function supports something like multiple
    expressions when it doesn't, it's hard to believe a study guide published by
    Macromedia Press would contain such a big mistake. Because it was so hard to
    believe I've spent quite a bit of time trying to get this to work, but in the
    end I think you are right, multiple expressions are simply not supported by
    IIf().

    xor3 Guest

  6. #5

    Default Re: IIF function question

    > Forta says, 'ColdFusion evaluates
    > multiple expressions from left to right and will return the rightmost
    > expression. Therefore, using scripting syntax, we could place a number of
    > expressions inside of the IIf() function and return the last one evaluated.'
    The evaluate() function works this way. IIF() doesn't (to my knowledge,
    although my knowledge is not exhaustive ;-)

    I think Ben is getting confused. Or are you misreading what he writes?
    Are you sure you're not missing a reference to evaluate() in there,
    somewhere?

    Anyway, here's the relevant docs:
    [url]http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/functi76.htm#wp1104252[/url]

    --

    Adam
    Adam Cameron Guest

  7. #6

    Default Re: IIF function question

    Hi Zoe, thanks for you reply as well. It helps to have others confirming the
    same results, so I know it's not just me going mad! I did email Ben about this
    through his website about this about 2 weeks ago now (I was looking at the
    errata for the book to make sure it wasn't already listed). Haven't heard
    anything back yet, but I will post it here if he ever replies to me.

    Donna

    xor3 Guest

  8. #7

    Default Re: IIF function question

    >> no mention of evaluating multiple statements

    Thats right, IIF() does not do this. However, as the op pointed out, this is
    something that the evaluate function can do. But even then the multiple
    expressions are not separated by semi-colons, rather by commas. And it i sth
    estrings themselves that are separated, not expressions withing the same
    string. As in:

    Evaluate("string 1","string 2","string 3", .. more here if needed)

    When using the IIF() function the strings you give to it are just single
    expressions that are avulated as Evaluate("single string expression only")

    IIF(something is true, Evaluate("single string expression only"),
    Evaluate("single string expression only"))

    When using the IIF() function you do not actually need to use the evaluate
    function as I just did explicitly, but thats basically what is happening.

    Would you mind indicating which page of the study guide makes this claim,
    perhaps even better, posting the exact wording and a description of the
    context? I can't belive Ben Forta would make a mistake like this, it seems
    to be a bit more than a simple typo?



    "xor3" <webforumsuser@macromedia.com> wrote in message
    news:d12og1$7nc$1@forums.macromedia.com...
    > I'm studying for my ColdFusionMX exam using Ben Forta's study guide. There
    > is
    > quite a bit of errata in the book, including code that simply doesn't
    > work.
    > It's very frustrating. I thought maybe if I posted some of these code
    > samples
    > here I could get a correct answer. It's not in the errata, so if anyone
    > could
    > shed some light on this one I would appreciate it: What will be the
    > output of
    > the following code?: <CFOUTPUT>#IIF(1 is 1,'1;2;3',''Hello'')#</CFOUTPUT>
    > According to the book the answer to this is 3. After reading Forta's
    > description of the IIF function I chose the right answer to this question
    > in
    > the book. Not having used IIF at all I then decided to have a play and
    > started
    > off by using this code. It doesn't work. Forta says, 'ColdFusion
    > evaluates
    > multiple expressions from left to right and will return the rightmost
    > expression. Therefore, using scripting syntax, we could place a number of
    > expressions inside of the IIf() function and return the last one
    > evaluated.' He
    > also says that multiple expressions are separated by semicolons. So based
    > on
    > that I figured the correct answer to the above question was 3.
    > Unfortunately,
    > the code doesn't actually work, so now I'm confused. My question is... Is
    > the
    > problem in the syntax of the expression 1 or is Forta's description of IIF
    > incorrect? If anyone can come up with the correct syntax for this code,
    > something that evaluates the 3 expressions that make up expression 1 and
    > returns 3 as the result I would love to see it. I've tried some variations
    > but
    > haven't found the correct one yet. I don't want to go into the exam with
    > false
    > information.
    >

    gumshoe Guest

  9. #8

    Default Re: IIF function question

    Der Nickname,

    First of all, we are not dealing with a list element here, but a series of
    statements, which (in cfscript, for example) are separated by a semicolon.

    Second, You're wrong again about that only TRUE/FALSE or a string could be
    returned. The DE() is used for displaying strings, otherwise function results
    can be displayed. For example, Iif(1 IS 1, "listlast('1;2;3',';')","'blah'")
    returns "3".

    Third, ...Where did you hear about CF from in the first place, if not from
    Ben?! ;-)

    Fernis Guest

  10. #9

    Default Re: IIF function question

    > First of all, we are not dealing with a list element here, but a series of
    > statements, which (in cfscript, for example) are separated by a semicolon.
    Maybe you should read the whole thread.

    > Second, You're wrong again about that only TRUE/FALSE or a string could be
    > returned.
    Who suggested this?

    > Third, ...Where did you hear about CF from in the first place, if not from
    > Ben?! ;-)
    Ben Forta is not the all-knowing guru his PR machine would have us think.
    He's pretty good with CF, but not exceptional (nor, I hasten to add, am I!
    ;-). Or maybe he is exceptionally good, but he dumbs his books down to the
    point of being bad advice, in some places. Could well be that.

    They are good beginners' books, though, no doubt about that.

    --

    Adam
    Adam Cameron Guest

  11. #10

    Default Re: IIF function question

    1. I know ;)
    2. Thank you for advising me, but I think ListLast() is another function, and
    a combination of functions wasn't questioned in this thread. So, IIF only
    results TRUE or FALSE, what means that IIF does output "3" in this case,
    because of ListLast. There isn't really a "1;2;3" string in IIF, it's just a
    "3", which is already filtered out of 1;2;3, by ListLast. It's a really
    philosophical question, isn't it?

    3. I'm autodidact. :)
    No, Perhaps it was Ben Forta, but the last book of CF I called my own was of
    CF 4.5, and I didn't really take care of names :)

    Der Nickname Guest

  12. #11

    Default Re: IIF function question

    Adam, I was replying to Der Nickname's comment. I read the whole thread,
    whereas you either didn't, or then the news groups don't update real-time with
    the web forums? Ok, let's forget that.

    Der Nickname, I took listlast() just as an example of a function. Maybe a bit
    confusing, since it's too close to the issue we're having here. :) Any
    functions can be performed of course. Fortunately IIF() can call a user-defined
    function, which then again may perform a series of actions.

    Fernis Guest

  13. #12

    Default Re: IIF function question

    > Adam, I was replying to Der Nickname's comment. I read the whole thread,
    > whereas you either didn't, or then the news groups don't update real-time with
    > the web forums? Ok, let's forget that.
    Yes, that's exactly what happened. Der Nickname's post showed up (11:56)
    for me not only after your reply (10:50), but after my reply to you
    (11:12)!

    I suspect the MM NNTP server gets confused about different TZs, or... just
    confused (it would not be the first time).

    So, yeah, sorry about that.

    --

    Adam
    Adam Cameron 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