Re: Finding if a key exists in a struct based on a variable name

2010-09-08 Thread Dominic Watson
On a side note, if you're after an output of 'yes' or 'no', this may be cleaner: #YesNoFormat( StructKeyExists(x.classAssign, #y#head) )# Dominic On 8 September 2010 02:30, Michael Grant mgr...@modus.bz wrote: So I went back and read the docs for IIF. I haven't looked at them in years and

Re: Finding if a key exists in a struct based on a variable name

2010-09-08 Thread Michael Grant
Thanks. I'm actually after the structvalue if it exists and a zero length string if it doesn't. It looks like Rex has me sorted though. Thanks Dom. On Wed, Sep 8, 2010 at 3:24 AM, Dominic Watson watson.domi...@googlemail.com wrote: On a side note, if you're after an output of 'yes' or 'no',

Finding if a key exists in a struct based on a variable name

2010-09-07 Thread Michael Grant
If my var y = myCell and I want to know if the key myCellHead exists in a struct how do I do it? I thought that the following would work in an IIF statement but it doesn't. iif(StructKeyExists(x.classAssign,#y#head),DE('yes'),DE('no')) Any ideas?

Re: Finding if a key exists in a struct based on a variable name

2010-09-07 Thread Raymond Camden
This should work fine: cfif structKeyExists(somestruct, #y#head) You don't need IIF at all. On Tue, Sep 7, 2010 at 3:04 PM, Michael Grant mgr...@modus.bz wrote: If my var y = myCell and I want to know if the key myCellHead exists in a struct how do I do it? I thought that the following

Re: Finding if a key exists in a struct based on a variable name

2010-09-07 Thread Michael Grant
I know, but I want it inline of an html tag, so that's why I wanted IIF instead of an if/else block. On Tue, Sep 7, 2010 at 4:15 PM, Raymond Camden rcam...@gmail.com wrote: This should work fine: cfif structKeyExists(somestruct, #y#head) You don't need IIF at all. On Tue, Sep 7,

Re: Finding if a key exists in a struct based on a variable name

2010-09-07 Thread Raymond Camden
It works for me: cfset x = {} cfset y = all cfoutput #iif(StructKeyExists(x,#y#head),DE('yes'),DE('no'))# /cfoutput p cfset x[allhead] = 1 cfoutput #iif(StructKeyExists(x,#y#head),DE('yes'),DE('no'))# /cfoutput I correctly get no/yes. On Tue, Sep 7, 2010 at 3:37 PM, Michael Grant

Re: Finding if a key exists in a struct based on a variable name

2010-09-07 Thread Michael Grant
Here's what I have: #iif(StructKeyExists(x.classAssign,#y#head),DE(x.classAssign[#y#head]),DE(''))# The error I get is: Element NAMEhead is undefined in a CFML structure referenced as part of an expression. Since I couldn't get it working I switched it to an if/else statement and got the

Re: Finding if a key exists in a struct based on a variable name

2010-09-07 Thread Raymond Camden
Looks pretty similar, but mine works: cfset x = {} cfset y = all cfoutput #iif(StructKeyExists(x,#y#head),DE('yes'),DE('no'))# /cfoutput p cfset x[allhead] = booger cfoutput #iif(StructKeyExists(x,#y#head),DE(x[#y#head]),DE('no'))# /cfoutput On Tue, Sep 7, 2010 at 3:55 PM, Michael Grant

Re: Finding if a key exists in a struct based on a variable name

2010-09-07 Thread Michael Grant
Try running this: cfset x = {} cfset y = all cfoutput #iif(StructKeyExists(x,#y#head),DE('yes'),DE('no'))# /cfoutput p !--- cfset x[allhead] = booger --- cfoutput #iif(StructKeyExists(x,#y#head),DE(x[#y#head]),DE('no'))# /cfoutput

Re: Finding if a key exists in a struct based on a variable name

2010-09-07 Thread Raymond Camden
Bah - I hacked away at it for 10 minutes before remembering why I hated IIF/DE in the first place. ;) On Tue, Sep 7, 2010 at 4:04 PM, Michael Grant mgr...@modus.bz wrote: Try running this: cfset x = {} cfset y = all cfoutput #iif(StructKeyExists(x,#y#head),DE('yes'),DE('no'))# /cfoutput

Re: Finding if a key exists in a struct based on a variable name

2010-09-07 Thread Michael Grant
HA! So I'm not the only one! So I thought DE meant Delay Evaluation as in Don't evaluate what's in these little brackets this until you've satisfied the IIF condition. I guess not? On Tue, Sep 7, 2010 at 5:14 PM, Raymond Camden rcam...@gmail.com wrote: Bah - I hacked away at it for 10 minutes

RE: Finding if a key exists in a struct based on a variable name

2010-09-07 Thread Andy Matthews
CF9 has the ternary operator which is awesome. Works like JavaScript: cfset output = (boolean ? It was True : It was False) andy -Original Message- From: Michael Grant [mailto:mgr...@modus.bz] Sent: Tuesday, September 07, 2010 4:17 PM To: cf-talk Subject: Re: Finding if a key exists

Re: Finding if a key exists in a struct based on a variable name

2010-09-07 Thread Michael Grant
Unfortunately I'm on CF8. And I wonder if the ternary operator would be able to handle a dynamic value as the output as with my example. IIF works perfect for exactly the type of example you gave; a simple boolean evaluated to output a simple string. The problem lies in CF apparently evaluating

Re: Finding if a key exists in a struct based on a variable name

2010-09-07 Thread rex
A lot of people get DE() wrong. IIF does not short-circuit (http://en.wikipedia.org/wiki/Short-circuit_evaluation), meaning that your DE() gets evaluated even if the condition is FALSE. So, this will break: #iif(false, notFalse, false)# since notFalse does not exist. Same here:

Re: Finding if a key exists in a struct based on a variable name

2010-09-07 Thread Michael Grant
Wow. I had no idea you could wrap DE in Evaluate. Did you come figure this out through trial and error or have I just never read it? Thanks for the post rex. On Tue, Sep 7, 2010 at 8:34 PM, rex li...@pgrworld.com wrote: A lot of people get DE() wrong. IIF does not short-circuit

Re: Finding if a key exists in a struct based on a variable name

2010-09-07 Thread Michael Grant
So I went back and read the docs for IIF. I haven't looked at them in years and I'm shocked that I've used it for SO many years without really knowing exactly how it worked. I would've first read about IIF pre version 5. I can't even find the docs for it. Version 5's description is a little