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

IIF function

Guest
Apr 18, 2006 Apr 18, 2006

Copy link to clipboard

Copied

Hi,

I'd be grateful if somebody could please help me out with this problem.

I actually want to write the following using the IIF statement:

<cfif temp gt 0>
<cfset label = "Over">
<cfelseif temp lt 0>
<cfset label = "Under">
<cfelse>
<cfset label = "-">
</cfif>

Note
If I output the variable label using the cfif, cfelseif and cfelse, it gives me the correct output, i.e. either "-", Over, or Under.


I tried the following to rewrite the above statement using the iif function:

<cfset label = iif(temp eq 0,DE("-"),(iif(temp gt 0,DE("Over"),DE("Under"))))>

Now, when temp eq 0, it works fine.
However, when temp is lt 0, it throws me an error message saying variable Under is undefined.
And when temp is gt 0, I get the same error message, but in this case it says variable Over is undefined.

However, if I replace Over and Under by 1 or 0 (i.e. integers) it works perfect!

Any idea how to get the output either Over or Under using the iif statement pls?

Thanks and regards,
Yogesh Mahadnac.
TOPICS
Advanced techniques

Views

381

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

correct answers 1 Correct answer

Participant , Apr 18, 2006 Apr 18, 2006
<cfset label = iif(temp eq 0,DE("-"),DE(iif(temp gt 0,DE("Over"),DE("Under"))))>

You needed a DE before your second iif.

Trevor
Don't Click Here

Votes

Translate

Translate
LEGEND ,
Apr 18, 2006 Apr 18, 2006

Copy link to clipboard

Copied

> I actually want to write the following using the IIF statement:

Not that you asked, but IMO this is a mistake, for the very reason you're
experiencing here: the iif() version of this code is quite difficult to
read (and easy to muck up, as you have).

WHY are you wanting to change it to an iif() expression?

> <cfset label = iif(temp eq 0,DE("-"),(iif(temp gt 0,DE("Over"),DE("Under"))))>

I *suspect* (strongly ~) this is because you are "escaping" the overs and
unders in the nested iff() call, but not in the result of the outer one.
So, if temp happens to be greater than zero, for all intents and purposes
you are left with this line of code:

iif(temp eq 0,DE("-"), "Over")

If this is the case, I think you need to have a DE() around you entire
second iif() expression.

BLEAH.

Stick with the CFML

(just opinion).

--
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
Participant ,
Apr 18, 2006 Apr 18, 2006

Copy link to clipboard

Copied

<cfset label = iif(temp eq 0,DE("-"),DE(iif(temp gt 0,DE("Over"),DE("Under"))))>

You needed a DE before your second iif.

Trevor
Don't Click Here

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
Guest
Apr 19, 2006 Apr 19, 2006

Copy link to clipboard

Copied

LATEST
Thanks a lot TSB!

That did the trick.

Cheers!

Yogesh

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