Using Boolean Attribute in IF statements?

I'm having trouble testing a object's boolean attribute value in an "if" statement.

I was expecting to be able to do it like this:
if (o."nameOfBoolAttribute") print "yes"

However, the following is the only approach I've been able to make work:
bool b = o."nameOfBoolAttribute"
if (b) print "yes"

Must one always go through the overhead of creating/assiging a local bool variable to test the value of an object's boolean attribute?
BobSherman - Sat Jan 29 07:35:19 EST 2011

Re: Using Boolean Attribute in IF statements?
kbmurphy - Sat Jan 29 11:40:02 EST 2011

Boolean attributes are just treated as text in DXL. So what you want is:

if (o."mybool" "" == "True" )
+ ack "True"+
else
+ ack "False"+

Re: Using Boolean Attribute in IF statements?
BobSherman - Mon Jan 31 06:35:42 EST 2011

Thanks very much; will use this approach.

Re: Using Boolean Attribute in IF statements?
llandale - Tue Feb 01 09:07:52 EST 2011

Yes, 'if (obj.MyBool "" == "True")' works. That's because a boolean attribute is just an enumerated attribute with two values, "True" and "False" (capital letters). However, there are some DXL perms that know that an attr ref is a boolean and translates it for you. Also, this works: "bool b = obj.MyBoolAttr" works but that has to do with the enumerations related number, turns false if its zero returns true otherwise.

Wrote this function and use it some, but I guess mostly because I have ADHD:


//************* bool    fBoolOf(string Value) 
{     
// Turn the string Value into a Boolean. 
// Specifically if (ignoring case) its exactly "True" (any case) return(true), 
//      otherwise return(false). 
// Note: The length check prevents massive memory leak in case this function 
//  is called with a huge string Value. 

if (length(Value) != 4) 

return(

false) 

return(lower(Value) == 
"true") 
}    
// end fBoolOf()

  • Louie