Ok
DE() is "Delay Evaluation"
Evaluate() immediately evaluates the expression
So when you do
IIF(structKeyExists(FORM, "key"), "FORM.key", DE("Empty String"))
It delays trying to retrieve FORM.key and evaluates it only if the condition
is true
With your example of #IIF(condition,"[a]","")# it would equate to
<cfif condition>
<cfset result = [a]>
<cfelse>
<cfset result = >
</cfif>
Which is why it errors
You said "I've been interpreting 'string_expression' to mean an expression
that returns a string" which is actually correct. The string you pass in IS
an expression but any variables you use in the expression still need to
exist.
I actually don’t use DE() inside IIF() anymore. What you can do is this...
IIF(structKeyExists(FORM, "key"), "FORM.key", "'Empty String'")
About your other question for "How do I do in-line case/switch expression?",
well you can next your IIF() functions so you could do something like..
IIF(structKeyExists(FORM, "key"), "IIF(FORM.key EQ 'hello', ""'welcome'"",
""'bye'"")", "'Empty String'")
...but then it starts to get a little cumbersome. Maybe a UDF or similar
would be better suited for what you are trying to do?
Steve
-----Original Message-----
From: Chris Velevitch [mailto:[email protected]]
Sent: Thursday, 16 September 2010 3:07 PM
To: [email protected]
Subject: [cfaussie] I don't understand why the IIF function works the way it
does
In CF 7, the function IIF (inline IF) usage is:-
IIf(condition, string_expression1, string_expression2)
which I initially interpreted to be the equivalent of:-
<cfif condition>
<cfset result = string_expression1>
<cfelse>
<cfset result = string_expression2>
</cfif>
but when I do:-
#IIF(condition,"[a]","")#
I get an error.
On closer inspection, it turns out that IIF is really the equivalent of:-
<cfif condition>
<cfset result = Evaluate(string_expression1)>
<cfelse>
<cfset result = Evaluate(string_expression2)>
</cfif>
I've been interpreting 'string_expression' to mean an expression that
returns a string, but really means a string (or string variable) that
contains an expression.
Why is this? How do I do in-line case/switch expression?
Chris
--
Chris Velevitch
Manager - Adobe Platform Users Group, Sydney
m: 0415 469 095
www.apugs.org.au
Adobe Platform Users Group, Sydney
September 2010: The "State of CFML" Address
Date: 27th September, 6pm for 6:30 start
Details and RSVP coming.
--
You received this message because you are subscribed to the Google Groups
"cfaussie" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cfaussie?hl=en.
--
You received this message because you are subscribed to the Google Groups
"cfaussie" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cfaussie?hl=en.