6 Replies Latest reply on May 25, 2008 2:52 PM by BKBK

    IIF Syntax

    djc11 Level 1
      Hey all,
      What is wrong with this statement? It is executing the 1st statement even when the condition is false.

        • 1. Re: IIF Syntax
          doug777 Level 1
          I have found that some cf functions don't handle functions within functions very well. I would try evaluating the the whole of the third argument first and then just putting the result into the function. At the very least it will help to see where the error is occurring.

          Doug
          • 2. Re: IIF Syntax
            Level 7
            Like all CF functions calls, CF parses each argument passed in to iif()
            before iif() gets a chance to do its thing. All three arguments
            (condition, value-to-return-if-true, value-to-return-if-false) need to be
            valid at run time, even if one of the latter two arguments isn't ultimately
            used.

            Did you read the docs for iif()?
            http://livedocs.adobe.com/coldfusion/8/functions_h-im_05.html

            --
            Adam
            • 3. Re: IIF Syntax
              BKBK Adobe Community Professional & MVP
              Hi Djc11,

              I find two things wrong with the statement. First, the equality sign right after cfset is no good. Secondly, throwing it all into one statement makes your code difficult to debug and to maintain. I would do something like the following.

              • 4. Re: IIF Syntax
                Level 7
                > I find two things wrong with the statement. First, the equality sign right
                > after cfset is no good.

                Why not? If one is not interested in the returned result of the operation,
                why bother storing it in a variable?

                With querySetCell() the object of the exeercise is to set the value in the
                passed-in query, not to capture whether the operation was a success.

                I can't say I have ever come across a situation in which querySetCell()
                returns false.


                > <cfset isCellSet = QuerySetCell(ErrorQuery, m, netNoOfHeads)>

                What is isCellSet subsqeuently used for? Not necessarily in this code, but
                say for example some of your code which would use querySetCell().

                I will agree that the original code is a bit difficult to follow. I'd just
                use an equivalent <cfif> statement rather than an iif() function call,
                rather thab horse around setting all those extra variables as per your
                example, though. They just seem like clutter rather than adding any
                clarify. But, you know, each to their own.

                --
                Adam
                • 5. Re: IIF Syntax
                  djc11 Level 1
                  OK. Thanks for all the feedback. The '=' sign right after the cfset was a typo but i typically never set QuerySetCell to a variable as i never need the result. I guess the problem is that the first condition is only viable if the condition is true. I have it set up in a cfif/else structure but i thought if i could make it a one line using a condition?s1:s2 type structure it would be more efficient but i guess it doesn't work like that. I did read the docs but didn't understand that part until i reread it.
                  • 6. Re: IIF Syntax
                    BKBK Adobe Community Professional & MVP
                    BKBK:
                    >> I find two things wrong with the statement. First,
                    >> the equality sign right after cfset is no good.


                    Adam Cameron:
                    > Why not?

                    Because it is a mistake.

                    >What is isCellSet subsqeuently used for? Not
                    > necessarily in this code, but say for example some of
                    > your code which would use querySetCell().


                    It is a boolean that tells you whether or not the data was successfully set in the query cell. It will be false if, for whatever reason, the operation failed to set the data in the query. It might be critical to your application to know that. However, I agree that using <cfset true> or <cfset isCellSet = true> is, to a certain extent, a matter of style.