• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Decision Functions

Decision Functions

The CFML decision functions return TRUE or FALSE values. They are often useful in <cfif> instructions to help in making decisions about what course of action to take within your scripts.

  • FileExists(file)— Returns TRUE if the specified file exists or FALSE otherwise. The following example tells whether there is a file called default.htm in the Web root directory:

    Home page exists? <cfoutput> 
    #FileExists("c:\inetpub\wwwroot\default.htm")#</cfoutput>
    
  • IsArray(variable)— Returns TRUE if the specified variable is an array or FALSE otherwise. The output from the following example would be YES, the string representation of TRUE:

    <cfset flavors = "chocolate,vanilla,strawberry"> 
    <cfset arrFlavors = ListToArray(flavors)>
    <cfoutput>#IsArray(arrFlavors)#</cfoutput>
    
  • IsBinary(value)— Returns TRUE if the specified value is binary or FALSE otherwise. The following example would print YES, the string representation of TRUE:

    <cfoutput>#IsBinary(100110110)#</cfoutput> 
    
  • IsBoolean(value)— Returns TRUE if the specified value can be converted to Boolean or FALSE otherwise. The output from the following example would indicate whether what a user typed in could be interpreted as a Boolean value:

    <cfif IsBoolean(Form.userInput)> 
       The data you entered can be interpreted as Boolean.
    <cfelse>
       The data you entered cannot be interpreted as Boolean.
    </cfif>
    
  • IsDate(string)— Returns TRUE if the specified string represents a valid date or FALSE otherwise. The following code shows how to check what a user typed in to make sure it can be converted into a date:

    <cfif not IsDate(Form.birthday)> 
       You did not enter a valid date for your birthday!
    </cfif>
    
  • IsDefined("variable")— Returns TRUE if the specified variable exists or FALSE otherwise. The variable's name must be in quotation marks. IsDefined() is useful for checking to see whether check box or radio button fields have been submitted. For example:

    <cfif not IsDefined("Form.age")> 
       You didn't specify your age range!
    </cfif>
    
  • IsLeapYear(number)— Returns TRUE if the specified number represents a leap year or FALSE otherwise. The following example would output NO, the string representation of FALSE:

    <cfoutput>#IsLeapYear(2003)#</cfoutput> 
    
  • IsNumeric(string)— Returns TRUE if the specified string can be converted to a number or FALSE otherwise. This function is useful for making sure that something is a number before you use it with a mathematical function. For example:

    <cfif IsNumeric(Form.number)> 
       <cfoutput>The base 10 logarithm of #Form.number# is
       #Log10(Form.number)#. </cfoutput>
    </cfif>
    
  • IsQuery(variable)— Returns TRUE if the specified variable is a query object or FALSE otherwise. The output from the following example would be YES, the string representation of TRUE, because Verity search results are stored in query object format:

    <cfsearch name="SearchResults" collection="mySite" criteria="#Form. keyword#"> 
    <cfoutput>#IsQuery(SearchResults)#</cfoutput>
    
    
    					  
  • IsSimpleValue(value)— Returns TRUE if the specified value is a string, number, Boolean, or date/time; it returns FALSE otherwise. The output from the following example would be NO, the string representation of FALSE, because Application is a structure and structures are not simple values:

    <cfoutput>#IsSimpleValue(Application)#</cfoutput> 
    
  • IsStruct(variable)— Returns TRUE if the specified variable is a structure or FALSE otherwise. The output from the following example would be YES, the string representation of TRUE:

    <cfoutput>#IsStruct(Session)#</cfoutput> 
    

PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint