About Me

Friday, 20 April 2012

ASP Comments

ASP Comments

As we have stated way too many times now, ASP uses VBScript as its default programming language. This means VBScript comments are ASP comments. It's a darn shame too because that means there isn't any support for multiple line comments that you see in HTML and various other programming languages.

ASP Comment Syntax: Single Line Comment

To create a comment in ASP you simply place an apostrophe in front of what you want commented out. The most common practice is to place the apostrophe at the beginning of the line of text like we have in the following example.

ASP Code:

<%
'Hello I am a comment
Dim newVar1, newVar2
'Dim oldVar1, oldVar2
%>
In the above example we had two comments. The first comment was a note style comment. Programmers often use these kinds of comments to leave information to people who are going to read their code or to themselves.
The second comment we created commented out "Dim oldVar1, oldVar2" preventing the ASP interpreter from reading this line of code. This kind of comment is a block-out comment that is often used to temporarily remove code from a file that may be causing errors or is just unnecessary at the time.

How Comments Fail in ASP

Besides not having any support for multi-line comments, your ASP comments will not work if you place them within a string. This is because the interpreter will think that your apostrophe is a part of the string and not a comment. Below is an example of this happening.

ASP Code:

<%
Dim newVar1, newVar2
newVar = "Hello.  'I am not commented out"
%>

0 comments:

Post a Comment