Server Time:
Sunday May 11 2008 08:18 PM  
Your Time:
  
HostMySite.Com is sponsoring this tutorial, please visit their site today!
This tutorial is sponsored by HostMySite.Com - ColdFusion Hosting

Boolean Saves Time, and Space
by: David Patricola
Email this tutorial to a friend Display Printer Friendly Format
[Download in PDF Format] [Download in FlashPaper Format]

Boolean Saves Time, and Space
by David Patricola <david.patricola@mindspring.com>

Boolean values can be a time trimmer when you're crunching 10 hours of code in a 5 hour deadline. IF statements can become quite burdensome at times, constantly typing out the conditional. With boolean values, you can shortcut that conditional typing slightly. Here is why.

<cfset flag = 1>
<cfset results =
"">

<cfif flag eq 1>
    <cfset results =
"foo">
<cfelse>
   <cfset results =
"bar">
</cfif>

Pretty simple, right? No hidden functionality here. Let's take a "little off the top", barbershop-style, showing you how I do it.

<cfset flag = 1>
<cfset results =
"">

<cfif flag>
     <cfset results =
"foo">
<cfelse>
     <cfset results =
"bar">
</cfif>


Voila! Overall, it's not much, but with IF statements in bulk this can be a helluva little trick.

How does it work? Well, the value of flag is set to "1". In boolean terms, 1 means true/on, while 0 means false/off (Access DB users will notice this as well). Since an IF statement, at its base, merely checks one of two possible conditions for a variable, this works perfectly.

<cfif flag> literally processes to <cfif 1>, and since 1 means "true", that part of the IF statement is executed.

Coincidentally, this technique can be done if your variable is has a value of "TRUE" or "FALSE", as ColdFusion treats these two words in the same manner as 1/0. Now, back to your regularly scheduled program.


Date added: Thu. July 24, 2003
Posted by: David Patricola | Views: 8029 | Tested Platforms: CF4,CF5,CFMX | Difficulty: Intermediate
Categories Listed: Databases Other Working w/Data

HostMySite.Com is sponsoring this tutorial, please visit their site today!
This tutorial is sponsored by HostMySite.Com - ColdFusion Hosting

This author's other tutorials:
E-mail Scramble
This simple CFC scrambles your e-mail into ASCII-equivalent characters, reducing the chance of your e-mail being phished by bots and spiders significantly. - Date added: Sun. July 9, 2006
Please rate this tutorial:
5 Stars 4 Stars 3 Stars 2 Stars 1 Stars
Post a new comment on this tutorial
post a new comment on this particular tutorial
Your Name:
Your Email:
Comment Title:
Comments:
Key Phrase:
 
Skyscrapper Banner Advertisement
ProWorkFlow.Com

You are 1 of 786 active sessions! | Privacy | Company
Copyright © 2002 EasyCFM.Com, LLC. (Easy ColdFusion Tutorials) All Rights Reserved
All other trademarks and copyrights are the property of their respective holders.
ColdFusion Hosting ColdFusion Hosting
ADD TO:
Blink
Del.icio.us
Digg
Furl
Google
Simpy
Spurl
Y! MyWeb