Programming

ColdFusion (CF)


Coldfusion is a scripting language that is used on web servers to merge web page output with optional content or results from a database or user input. Web pages by themselves are static, but intelligence placed on the web server through programs (like Coldfusion) allow a web page to change based on data it gets from the user or from other sources.

Download software: Coldfusion

Cost: Free

Instructions to setup software: http://www.learncfinaweek.com/week1/

Hardware requirements: PC, Mac

Operating systems supported: Win, Mac, Linux

Difficulty level: 4 out of 5


TRY IT!

1. Create a folder on your hard drive – call it “CF Demo”

2. Copy this Coldfusion and HTML code and paste into your favorite text editor. Windows notepad works fine.


<!---Coldfusion Document --->
<!--- Note: lines that start with the characters highlighted in yellow are comments - not code! --->
<cffunction name="convertTemperature"> 
	<cfargument name="temperature" type="numeric" required="true">
		<cfset returnText = "You converted " & #round(temperature)# & "#chr(186)#  F to " & #round((temperature - 32) / 1.8)# & "#chr(186)#  C"> 
		<cfif temperature LT 32>
			<cfset returnText = returnText & ": Pack Long Underwear">
		<cfelseif temperature GT 100 >
			<cfset returnText = returnText & ": Remember to Hydrate">
		</cfif>

		<cfreturn returnText>
</cffunction>

<cfoutput>	
<head> 
	<title>BSA Coldfusion Temperature Conversion</title> 
</head> 
<body> 
	<h2>BSA Coldfusion Temperature Conversion</h2> 
	<cfif isDefined("form.SubmitConvert")>
		<cfif isDefined("form.temperature") and Not val(form.temperature)>
			<strong>Please enter only numbers for the temperature</strong>	
		<cfelse>
			#convertTemperature(form.temperature)#
		</cfif>
		
	</cfif>
	<cfform name="form">
		<P>Enter a number in the box below to convert the temperature to Celcius.</P>
		Degrees: <input name="temperature" type="text" size=5>
		         <input name="SubmitConvert" type="submit">
	</cfform>
</body>
</cfoutput>

3. Save the File as “CF-Example.cfm” in the new folder you created in step 1. cfm as the extension stands for coldfusion markup. Other forms of Coldfusion extensions are cfc or cfml.

4. Double click on the CF-Example.cfm file to launch a browser. Enter a temperature and click the Submit Button to see the result. Try several different temperatures.


ABOUT THE PROGRAM — A WALK THROUGH

1. The HTML within the file defines the text and formatting information for a simple web page. Coldfusion and HTML are usually written together. HTML wraps the Coldfusion code. You can change anything you want to see how it affects the formatting of the page. This isn’t really programming, but it is fun to play with. It:

a. Creates a title for the website

b. Tells the HTML code to use Coldfusion and where to find the code

c. Formats the displayed text

d. Specifies a text entry box with ID = “temperature” (Coldfusion will need this)

e. Specifies a button labeled “Submit!”

f. When the mouse button is pressed, runs the CF convertTemperature function

g. Displays the string in “returnText” which is created in the CF function.

2. The CF form collects all the information that needs to be interpreted and sends the information to CF to be used.

a. Cf has its own set of input fields. One of them is the Submit type. When used it creates a button that submits the form.

3. Once the submit button is pressed, the form submits the information into the following block of code. It looks to see the function has been called, if not it calls the convertTemperature function with the cfinput variable. There is some basic error handling in the function to check that the input is a number.


<cfif isDefined("form.SubmitConvert")>
		<cfif isDefined("form.temperature") and Not val(form.temperature)>
			<strong>Please enter only numbers for the temperature</strong>	
		<cfelse>
			#convertTemperature(form.temperature)#
		</cfif>
</cfif>

4. The “convertTemperature ” function

a. Obtains the value entered in the “Input”-“Text” tag by using it’s ID: “temperature”

b. The value is converted to Celcius (with a single decimal place).

c. The Celcius value is evaluated with a series of IF Statements and a suggested action phrase is assigned to the variable: “returnText”

d. A sentence is created by combining or “concatenating” some static text along with the temperature values (deg F and Deg C) and the action phrase.

e. The new phrase is inserted onto the top of the HTML page the return variable from the function.


TRY THIS

1. Change the temperatures used in the decisions – change the lower temperature from 60 to 30 degrees, for example. Make sure you change it in two places! Save the file and refresh the browser (or restart the web page), and enter new numbers – did the answers change at the new temperature?

2. Create a new temperature range from 30 to 60 degrees and have it display – “Bring hat and gloves!”

3. Change the wording of the phrases

4. Take out the error handling and send in a letter. Leave only the part below.

	#convertTemperature(form.temperature)#

5. Add another text input – ask for the wind speed, for example

6. Add some conditional statements that evaluate the wind chill factor

7. Add some text to display the wind chill result


LEARN MORE

Adobe Coldfusion – This is Adobe’s resource for getting started with Coldfusion


RESOURCES, TIPS, TRICKS AND HINTS

Notepad++ is a great free text editor designed specifically for programmers. Check it out here.

Write a comment about “ColdFusion (CF)”

Nickname:

Type your comment:

  • 1. Safety. Do the following:
      a. Show your counselor your current, up-to-date Cyber Chip.
      b. Discuss first aid and prevention for the types of injuries or illnesses that could occur during programming activities, including repetitive stress injuries and eyestrain.

    2. History. Do the following:
      a. Give a brief history of programming, including at least three milestones related to the advancement or development of programming.
      b. Describe the evolution of programming methods and how they have improved over time.

    3. General knowledge. Do the following:
      a. Create a list of 10 popular programming languages in use today and describe which industry or industries they are primarily used in and why.
      b. Describe three different programmed devices you rely on every day.

    4. Intellectual property. Do the following:
      a. Explain how software patents and copyrights protect a programmer.
      b. Describe the difference between licensing and owning software.
      c. Describe the differences between freeware, open source, and commercial software, and why it is important to respect the terms of use of each.

    5. Projects. Do the following:
      a. With your counselor’s approval, choose a sample program. Then, as a minimum, modify the code or add a function or subprogram to it. Debug and demonstrate the modified program to your counselor.
      b. With your counselor’s approval, choose a second programming language and development environment, different from those used for requirement 5a and in a different industry from 5a. Then write, debug, and demonstrate a functioning program to your counselor, using that language and environment.
      c. With your counselor’s approval, choose a third programming language and development environment, different from those used for requirements 5a and 5b and in a different industry from 5a or 5b. Then write, debug, and demonstrate a functioning program to your counselor, using that language and environment.
      d. Explain how the programs you wrote for requirements 5a, 5b, and 5c process inputs, how they make decisions based on those inputs, and how they provide outputs based on the decision making.

    6. Careers. Find out about three career opportunities in programming. Pick one and find out the education, training, and experience required. Discuss this with your counselor and explain why this career might be of interest to you.

  • Earning the Cyber Chip can help you learn how to stay safe while you are online and using social networks or the latest electronic gadgets.

    Topics include cell phone use, texting, blogging, gaming, cyberbullying, and identity theft. Find out more about the Cyber Chip at www.scouting.org/cyberchip.