Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
xor3 #1
IIF function question
I'm studying for my ColdFusionMX exam using Ben Forta's study guide. There is
quite a bit of errata in the book, including code that simply doesn't work.
It's very frustrating. I thought maybe if I posted some of these code samples
here I could get a correct answer. It's not in the errata, so if anyone could
shed some light on this one I would appreciate it: What will be the output of
the following code?: <CFOUTPUT>#IIF(1 is 1,'1;2;3',''Hello'')#</CFOUTPUT>
According to the book the answer to this is 3. After reading Forta's
description of the IIF function I chose the right answer to this question in
the book. Not having used IIF at all I then decided to have a play and started
off by using this code. It doesn't work. Forta says, 'ColdFusion evaluates
multiple expressions from left to right and will return the rightmost
expression. Therefore, using scripting syntax, we could place a number of
expressions inside of the IIf() function and return the last one evaluated.' He
also says that multiple expressions are separated by semicolons. So based on
that I figured the correct answer to the above question was 3. Unfortunately,
the code doesn't actually work, so now I'm confused. My question is... Is the
problem in the syntax of the expression 1 or is Forta's description of IIF
incorrect? If anyone can come up with the correct syntax for this code,
something that evaluates the 3 expressions that make up expression 1 and
returns 3 as the result I would love to see it. I've tried some variations but
haven't found the correct one yet. I don't want to go into the exam with false
information.
xor3 Guest
-
Function Question
Hi! Is there a considerable degredidation in speed if I where to include an ASP page into every other ASP page that would contain all the... -
Simple AS function question
Why will this not work home_btn.onRollOver = setInterval(delayAction,2000,home); function delayAction (framename:String) var name:String =... -
PHP function question
When writing a function that takes in a variable number of parameters and processing it using func_get_args or a similar technique, I'm assuming... -
utf8_decode function question
Hi folks, I read in a security note that something known as a cross-site scripting attacker can use utf8 encoding and that you could decode data to... -
Question: ConnectToDatabase function
Thanks! I wasn't sure if the Try code would continue or not if an exception was "caught". Now I know it doesn't. "Marina" <mzlatkina@hotmail.com>... -
Der Nickname #2
Re: IIF function question
Try to Use DE
<CFOUTPUT>#IIF(1 is 1,DE('1;2;3'),DE('Hello'))#</CFOUTPUT>
Der Nickname Guest
-
zoeski80 #3
Re: IIF function question
Der Nickname using your code it will output '1;2;3' , according to Ben's book
it should only return '3'.
I have been trying to get it to work on CF 6.1 and haven't had any luck.
Fernis, I agree, I thought what was in the TRUE/FALSE expressions was just
evaluated/output, didn't think it would accept multiple expressions.
The book didn't come with a CD containing the working examples did it?
Might want to try to get a response from [email]Ben@forta.com[/email] before you exam to
clear this issue up. Would be interested to see what you find out.
Zoe
zoeski80 Guest
-
xor3 #4
Re: IIF function question
Hi Fernis, and thanks! I think you are right, I have been reading up on IIf in
a few other references, including the Macromedia CF reference pdf and there is
no mention of evaluating multiple statements. Since posting this I have also
tried other code from the book which uses multiple expressions in one
expression and they too come up with errors. So thanks for confirming this with
your findings... I have hit a couple snags in the book like this and it slows
me down significantly as I keep trying to get it to work. It's a pretty
significant error to say that the function supports something like multiple
expressions when it doesn't, it's hard to believe a study guide published by
Macromedia Press would contain such a big mistake. Because it was so hard to
believe I've spent quite a bit of time trying to get this to work, but in the
end I think you are right, multiple expressions are simply not supported by
IIf().
xor3 Guest
-
Adam Cameron #5
Re: IIF function question
> Forta says, 'ColdFusion evaluates
The evaluate() function works this way. IIF() doesn't (to my knowledge,> multiple expressions from left to right and will return the rightmost
> expression. Therefore, using scripting syntax, we could place a number of
> expressions inside of the IIf() function and return the last one evaluated.'
although my knowledge is not exhaustive ;-)
I think Ben is getting confused. Or are you misreading what he writes?
Are you sure you're not missing a reference to evaluate() in there,
somewhere?
Anyway, here's the relevant docs:
[url]http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/functi76.htm#wp1104252[/url]
--
Adam
Adam Cameron Guest
-
xor3 #6
Re: IIF function question
Hi Zoe, thanks for you reply as well. It helps to have others confirming the
same results, so I know it's not just me going mad! I did email Ben about this
through his website about this about 2 weeks ago now (I was looking at the
errata for the book to make sure it wasn't already listed). Haven't heard
anything back yet, but I will post it here if he ever replies to me.
Donna
xor3 Guest
-
gumshoe #7
Re: IIF function question
>> no mention of evaluating multiple statements
Thats right, IIF() does not do this. However, as the op pointed out, this is
something that the evaluate function can do. But even then the multiple
expressions are not separated by semi-colons, rather by commas. And it i sth
estrings themselves that are separated, not expressions withing the same
string. As in:
Evaluate("string 1","string 2","string 3", .. more here if needed)
When using the IIF() function the strings you give to it are just single
expressions that are avulated as Evaluate("single string expression only")
IIF(something is true, Evaluate("single string expression only"),
Evaluate("single string expression only"))
When using the IIF() function you do not actually need to use the evaluate
function as I just did explicitly, but thats basically what is happening.
Would you mind indicating which page of the study guide makes this claim,
perhaps even better, posting the exact wording and a description of the
context? I can't belive Ben Forta would make a mistake like this, it seems
to be a bit more than a simple typo?
"xor3" <webforumsuser@macromedia.com> wrote in message
news:d12og1$7nc$1@forums.macromedia.com...> I'm studying for my ColdFusionMX exam using Ben Forta's study guide. There
> is
> quite a bit of errata in the book, including code that simply doesn't
> work.
> It's very frustrating. I thought maybe if I posted some of these code
> samples
> here I could get a correct answer. It's not in the errata, so if anyone
> could
> shed some light on this one I would appreciate it: What will be the
> output of
> the following code?: <CFOUTPUT>#IIF(1 is 1,'1;2;3',''Hello'')#</CFOUTPUT>
> According to the book the answer to this is 3. After reading Forta's
> description of the IIF function I chose the right answer to this question
> in
> the book. Not having used IIF at all I then decided to have a play and
> started
> off by using this code. It doesn't work. Forta says, 'ColdFusion
> evaluates
> multiple expressions from left to right and will return the rightmost
> expression. Therefore, using scripting syntax, we could place a number of
> expressions inside of the IIf() function and return the last one
> evaluated.' He
> also says that multiple expressions are separated by semicolons. So based
> on
> that I figured the correct answer to the above question was 3.
> Unfortunately,
> the code doesn't actually work, so now I'm confused. My question is... Is
> the
> problem in the syntax of the expression 1 or is Forta's description of IIF
> incorrect? If anyone can come up with the correct syntax for this code,
> something that evaluates the 3 expressions that make up expression 1 and
> returns 3 as the result I would love to see it. I've tried some variations
> but
> haven't found the correct one yet. I don't want to go into the exam with
> false
> information.
>
gumshoe Guest
-
Fernis #8
Re: IIF function question
Der Nickname,
First of all, we are not dealing with a list element here, but a series of
statements, which (in cfscript, for example) are separated by a semicolon.
Second, You're wrong again about that only TRUE/FALSE or a string could be
returned. The DE() is used for displaying strings, otherwise function results
can be displayed. For example, Iif(1 IS 1, "listlast('1;2;3',';')","'blah'")
returns "3".
Third, ...Where did you hear about CF from in the first place, if not from
Ben?! ;-)
Fernis Guest
-
Adam Cameron #9
Re: IIF function question
> First of all, we are not dealing with a list element here, but a series of
Maybe you should read the whole thread.> statements, which (in cfscript, for example) are separated by a semicolon.
Who suggested this?> Second, You're wrong again about that only TRUE/FALSE or a string could be
> returned.
Ben Forta is not the all-knowing guru his PR machine would have us think.> Third, ...Where did you hear about CF from in the first place, if not from
> Ben?! ;-)
He's pretty good with CF, but not exceptional (nor, I hasten to add, am I!
;-). Or maybe he is exceptionally good, but he dumbs his books down to the
point of being bad advice, in some places. Could well be that.
They are good beginners' books, though, no doubt about that.
--
Adam
Adam Cameron Guest
-
Der Nickname #10
Re: IIF function question
1. I know ;)
2. Thank you for advising me, but I think ListLast() is another function, and
a combination of functions wasn't questioned in this thread. So, IIF only
results TRUE or FALSE, what means that IIF does output "3" in this case,
because of ListLast. There isn't really a "1;2;3" string in IIF, it's just a
"3", which is already filtered out of 1;2;3, by ListLast. It's a really
philosophical question, isn't it?
3. I'm autodidact. :)
No, Perhaps it was Ben Forta, but the last book of CF I called my own was of
CF 4.5, and I didn't really take care of names :)
Der Nickname Guest
-
Fernis #11
Re: IIF function question
Adam, I was replying to Der Nickname's comment. I read the whole thread,
whereas you either didn't, or then the news groups don't update real-time with
the web forums? Ok, let's forget that.
Der Nickname, I took listlast() just as an example of a function. Maybe a bit
confusing, since it's too close to the issue we're having here. :) Any
functions can be performed of course. Fortunately IIF() can call a user-defined
function, which then again may perform a series of actions.
Fernis Guest
-
Adam Cameron #12
Re: IIF function question
> Adam, I was replying to Der Nickname's comment. I read the whole thread,
Yes, that's exactly what happened. Der Nickname's post showed up (11:56)> whereas you either didn't, or then the news groups don't update real-time with
> the web forums? Ok, let's forget that.
for me not only after your reply (10:50), but after my reply to you
(11:12)!
I suspect the MM NNTP server gets confused about different TZs, or... just
confused (it would not be the first time).
So, yeah, sorry about that.
--
Adam
Adam Cameron Guest



Reply With Quote

