• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

IIF Syntax

Explorer ,
May 23, 2008 May 23, 2008

Copy link to clipboard

Copied

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

TOPICS
Advanced techniques

Views

647

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 23, 2008 May 23, 2008

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 24, 2008 May 24, 2008

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 24, 2008 May 24, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 24, 2008 May 24, 2008

Copy link to clipboard

Copied

> 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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 24, 2008 May 24, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 25, 2008 May 25, 2008

Copy link to clipboard

Copied

LATEST
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.


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation