Lesson 7: Comment your scripts

As you may have noticed, ASP scripts can easily look confusing. In this lesson, we cover why comments are important and how to insert them into your scripts.

Why is it important to comment your scripts?

When you are coding, you are writing commands to a server/computer and need to use a highly formal language which may not clearly reflect your thoughts when making the script.

Therefore, it can be difficult for others (or yourself) to understand how the script is structured, and thus hard to identify and correct errors in the script.

Comments can be used to write short explanatory text in the script. The server completely ignores the comments, and the comments do not affect the actual functionality of the script.

In the business world, it is often a requirement that scripts and programming are commented, otherwise it would be too risky for a company to take over a system in which it would be too difficult to find and correct errors.

How do you insert comments?

It is quite easy to insert a comment. You simply start the comment with an apostrophe: " ' ".

Take a look at this example from lesson 5, now with comments:


	<html>
	<head>
	<title>Loops</title>
	</head>
	<body>

	<%
	' Here we write color codes using three loops

	' Three variables for the colors (red, green and blue)
	' and a variable for the color code:
	Dim intRed, intGreen, intBlue, strColor

	' Red can be between 0 and 255
	For intRed = 0 to 255 Step 30

	   ' Green can be between 0 and 255	

	   For intGreen = 0 to 255 Step 30

	      ' Blue can be between 0 and 255
	      For intBlue = 0 to 255 Step 30

	      ' The color code is made on the form rgb(red,green,blue)

	      strColor = "rgb(" & intRed & "," & intGreen & "," & intBlue & ")"

		  
	      ' Now we write the color code to the client

	      Response.Write "<span style='color: " & strColor & "'>" & strColor & " </span>"

	      ' Repeat loop
	      Next
	   Next
	Next
	%>

	</body>

	</html>

	
	

For the sake of the example, we have included many extra comments, so it should be clear that you are far better off debugging a script with comments than without.

Therefore, remember to comment your scripts!



<< Lesson 6: Conditions

Lesson 8: Arrays >>