ColdFusion MX: From Static to Dynamic in 10 Steps

Team-Fly    

ColdFusion® MX: From Static to Dynamic in 10 Steps

By Barry Moore

Table of Contents
Step 4.  Controlling Program Flow

The preceding example worked all right, but it wasn't all that accurate. For example, it would still say "Good Afternoon" at 11:30 at night. In this example, we will use several <CFELSEIF> statements to tighten things up a bit.

  1. In your text editor, type the code shown in Listing 4.2, or you can open the Greeting2.cfm file from the CompletedFiles\Examples\Step04 folder.

    Listing 4.2 Greeting2.cfm

    <!--- File: Greeting2.cfm Description: Demonstrate the use of <CFELSEIF> Author: Created: ---> <HTML> <HEAD> <TITLE>Daily Greeting 2</TITLE> </HEAD> <BODY> <!--- Check the time and customize the greeting based on the hour Use the Now() function to get the current Date and time Use the Hour() function isolate just the hour The Hour() function returns a value of 0 - 23 ---> <H2> <!--- To save a little typing, set the a variable equal to the value of the current hour ---> <CFSET TheHour = Hour(Now())> <CFIF TheHour LT 05> It is just way too early, <CFELSEIF TheHour LT 12> Good morning, <CFELSEIF TheHour LT 18> Good afternoon, <CFELSE> Good evening, </CFIF> welcome to my site. </H2> <P>I am glad you could make it.</P> </BODY> </HTML>

  2. Save this file in your Step04 directory as Greeting2.cfm.

  3. Browse to the file and have a look at the display. Change your system time to test each condition.


    Team-Fly    
    Top
     

    Категории