25

The way I know of hashing out code within ASP Classic is <%-- --%>. Would this be correct? Or is there another way?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Developer Jay
  • 953
  • 1
  • 10
  • 15
  • 3
    possible duplicate of [Server-side comments: What's the equivalent of <%-- --%> in classic ASP?](http://stackoverflow.com/questions/4431170/server-side-comments-whats-the-equivalent-of-in-classic-asp) – jlew Jun 05 '13 at 11:58
  • <% 'another way %> – Caique Romero Aug 18 '17 at 19:31

5 Answers5

27

Use a single quote, like:

' This is comment

ASP Classic uses the VBScript/Visual Basic language, and a single quote is commenting in that; <%-- is nothing (I am not 100% sure though).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sumit Gupta
  • 2,152
  • 4
  • 29
  • 46
  • what if I wanted to hash out the code ? For debugging and testing? – Developer Jay Jun 05 '13 at 11:59
  • I really don't recall how to comment out multiple line, like we have in C, etc. So all you can do is put single quote in front of every line you want to comment out, it comment out all lines. Sometime when I get lazy I delete such code and put in "Notepad" :) and paste it back... – Sumit Gupta Jun 05 '13 at 12:03
  • 1
    Some IDE support a feature which preprend or remove the quotes, allowing to comment/uncomment large blocks easily. – MaxiWheat Jun 05 '13 at 12:12
  • You can tell how old classic asp is, when developing in asp.net it was much easier to comment code out, but thanks Sumit :) – Developer Jay Jun 05 '13 at 12:17
  • If you are using Visual Studio you can still use that Shortcut to Ctrl+K,C to comment code in ASP. I think WebMatrix too support it. But Classic ASP within itself doesn't support multiline commenting as I know. – Sumit Gupta Jun 06 '13 at 05:33
7

Beside ', you can comment lines in the old school way:

 REM Response.Write "Ignore this line"

Which is same with

 ' Response.Write "Ignore this line"
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
cem
  • 1,535
  • 19
  • 25
4

Assuming you mean that you have large block of inline code like the below you want to disable:

<%
    CallSomething()
    DoSomething()
    Response.Write("all done")
%>

Then either comment out each line as described in this other answer or other approach is:

  1. Create a dummy, empty file called "dummy.asp" and place it in the same folder.
  2. Change the code block to this:

    <script language="vbscript" runat="server" src="dummy.asp">
        CallSomething()
        DoSomething()
        Response.Write("all done")
    </script>
    

    Note: you need to change only the <% and %>, all other lines can stay intact. Having a src in the script tag will cause the Classic ASP engine to take the file contents instead of taking the script block contents.

Then when you want to uncomment, either do it for each line or put back the <% and %>.

Community
  • 1
  • 1
Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
  • 2
    this is actually a pretty decent idea for large code blocks, thanks – Mike Corcoran Apr 01 '15 at 15:10
  • @Peter your edit ruined the list formatting (that part is part of the second bullet) and it's Classic ASP, not ASP Classic - that's how programmers know this for long years anyway and I'm not going to change it even if for some very odd reason the "correct" term is ASP Classic. So rolled back the edit, though I did add a missing comma and upper case "C". Thanks! – Shadow The GPT Wizard Apr 07 '17 at 20:35
  • 1
    Just a note for users of NOTEPAD++ as their IDE. Visually if you put some notes into place inline, it will discolor the HTML segments. So if that happens instead of an inline comment like <% 'this is the comment %>. You would instead put the close tag %> on the NEXT line and then the feedback of the coloring system of the HTML vs ASP embeds will display properly. However, this is NOT required, but if you don't do it, the visual display of the HTML sections will be displayed in NOTEPAD++ at least the wrong color until you put some of those close tags onto their own line. – easleyfixed Dec 10 '21 at 15:57
3

The question says... ASP classic.....

All the above answers are good, but specific to VBScript.

But a classic ASP file can also contain HTML and Javascript

Commenting VBScript code in a classic ASP file:

Refer any of the approved answers.

Commenting HTML code in a classic ASP file:

Refer https://www.w3schools.com/TAGS/tag_comment.asp

Commenting Javascript code in a classic ASP file:

Refer https://www.w3schools.com/js/js_comments.asp

Pavan Chandaka
  • 11,671
  • 5
  • 26
  • 34
0

This is the best way to comment out large blocks of code:

<%if 1=2 then%>

html or other code here

<%end if%>
  • Why not just `if false then` – LukasKroess Oct 02 '19 at 09:41
  • Of course it does, but why? Why have the code make a comparison at runtime of which the outcome you already know (hopefully!) – LukasKroess Oct 03 '19 at 13:18
  • @LuluCross I was told to use that by a very experienced programmer for large blocks of code. I am always willing to learn a better way. Isn't "if false then" running code unnecessarily too? Let me know what you use. – AspClassic-Guy Oct 03 '19 at 17:16
  • true, both variants work in just the same way, and the outcome is always that the code inbetween doesn't get executed, because it is "locked" behind a condition that can never be true. However (and granted no profiler would ever notice such a tiny difference in performance) `1=2` has to be "calculated" first every time, so that the compiler knows the expression equals false, whereas `false` is already false. Basically you have the compiler do a unneccessary equation, since the outcome is already known and could just as well be written as such. – LukasKroess Oct 07 '19 at 14:13
  • Thank you, I appreciate that. – AspClassic-Guy Oct 07 '19 at 19:14