House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

Just a tidbit for those who might not have use iif before

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Peterson, Chris
03/22/2007 04:11 PM

I have never really used iif before, I was aware it existed but didn't really see a good place for it.  Until today. =) Check this out: dollarformat(iif(Cost, cost, 0)) That says, evaluate cost as a Boolean, if its true (anything but 0 or null) then return cost, otherwise return 0 (so the dollarFormat does not break)  This is great instead of a <cfif> around the whole thing. Kinda cool =) Chris

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Rob Wilkerson
03/22/2007 04:16 PM

Uh oh.  You're probably about to get hammered with responses related to the performance cost... ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
John Rossi
03/22/2007 04:21 PM

...and about whether Cost is truly a Boolean... Uh oh.  You're probably about to get hammered with responses related to the performance cost... ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Andy Matthews
03/22/2007 04:18 PM

Here come the Iif police. I have never really used iif before, I was aware it existed but didn't really see a good place for it.  Until today. =) Check this out: dollarformat(iif(Cost, cost, 0)) That says, evaluate cost as a Boolean, if its true (anything but 0 or null) then return cost, otherwise return 0 (so the dollarFormat does not break)  This is great instead of a <cfif> around the whole thing. Kinda cool =) Chris

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Heald, Timothy J
03/22/2007 04:22 PM

Quick, someone find a way to make that need an evaluate(). Here come the Iif police. I have never really used iif before, I was aware it existed but didn't really see a good place for it.  Until today. =) Check this out: dollarformat(iif(Cost, cost, 0)) That says, evaluate cost as a Boolean, if its true (anything but 0 or null) then return cost, otherwise return 0 (so the dollarFormat does not break)  This is great instead of a <cfif> around the whole thing. Kinda cool =) Chris

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Rob Wilkerson
03/22/2007 06:35 PM

I think I heard something about them going back on tour this year... ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Justin Scott
03/22/2007 04:25 PM

> dollarformat(iif(Cost, cost, 0)) You could also use the val() function around the cost variable to do the same thing more efficiently.  It will also correct for unexpected non-integer characters in the variable as well.  I've found that in almost any situation where iif() looks like it's needed, there's a better way.  There are exceptions, but I don't think this is one of them. -Justin Scott

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Richard Cooper
03/23/2007 03:41 AM

I'm assuming there is a noticeable difference in using IFF? Recently I've been using it quite heavily in forms now i.e. <cfinput type="radio" name="myField" id="myField" value="myValue" checked="#IIF(something eq 'somethingelse', DE('Yes'), DE('No'))#" /> Are there better ways of doing this?

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Rob Wilkerson
03/23/2007 07:34 AM

checked="#something eq 'somethingelse#" That should work just fine.  No need for the iff() in this case. ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Peter Boughton
03/23/2007 09:10 AM

First better way: Don't use strings for booleans! <cfinput type="radio" name="myField" id="myField" value="myValue" checked="#IIF(something eq 'somethingelse', 1, 0)#" /> Second better way: Don't write "if True then True else False"! <cfinput type="radio" name="myField" id="myField" value="myValue" checked="#(something eq 'somethingelse')#" /> (parenthesis are unnecessary here, but I feel they make it more readable) Third better way: Don't use cfform! <form:select id="myField" options="myValue" value="somethingelse"/> (that's from my form custom tag library, not yet released) :) ----- Excess quoted text cut - see Original Post for more -----


<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

May 24, 2012

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
     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     

Designer, Developer and mobile workflow conference