Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp classic vBscript line beginning with //

I found in one of my old asp classic pages a line of vbScript code beginning with // and it was an error (commenting a line with // instead of ').

I noted anyway that the mistaken commented line works as a correct commented line. Someone knows why ?? Thanks a lot Leonardo

I made a small example taken from that old code:

<%
Response.Write "<u>testAsp.asp</u><hr/>" 
V_Password="pwd"
//V_Password = Str2Hex(V_Password)

Response.Write "V_Password=" + V_Password + "<br/>"
Response.Write "V_Password(hex)=""" + Str2Hex(V_Password) + """"

function Str2Hex(s)
' -- converte stringa di byte (non caratteri ascii!!) in formato esadecimale
'
'    The Asc function returns the ANSI character code corresponding 
'    to the first letter in a string.
'    The AscB function is used with byte data contained in a string. 
'    Instead of returning the character code for the first character, 
'    AscB returns the first byte. 
'    AscW is provided for 32-bit platforms that use Unicode characters. 
'    It returns the Unicode (wide) character code, thereby avoiding 
'    the conversion from Unicode to ANSI.

  dim k, out, MultiByte
  out=""
  for k=1 to len(s)
    'response.Write("|" & hex(ascb(Mid(s,k,1))) & "|<br>" & vbCrLf)
    out=out & hex(ascb(mid(s,k,1)))
  next
  Str2Hex="0x" & out
  'response.write(out & vbCrLf)
end function

%>

This is the produced output:

enter image description here

As you can see the asp page is in vbScript and contains also correct vbscript comments...

like image 527
Leonardo Danza Avatar asked Jul 02 '26 18:07

Leonardo Danza


1 Answers

Update

So I've done a bit of digging since you posted the example code and confirm that in a Classic ASP environment the code runs without error and appears to behave like a comment.

What I can confirm though is this is specific to a Classic ASP environment. If I try to run the example using wscript.exe as the host instead of Classic ASP I get the following error;

Microsoft VBScript compilation error: Expected statement

The only conclusion I can come to is it's a peculiar side-effect of support for both VBScript and JScript that means the ASP pre-processor doesn't cause the VBScript Runtime to throw a compilation error.

The likelihood is it's an accident that never got picked up because the page didn't force a compilation error as running the VBScript natively would.


Original Answer for Prosperity

Chances are the Classic ASP page was set to use JScript instead of VBScript. Both are available as default Active Scripting languages out if the box.

It might not always be clear what is in use as what scripting language is used by default can be set at the IIS website level rather than using the @language directive or a <script runat="server"> block.

Comments in VBScript come in two flavours, there are the Rem statement and the ' character. Starting a line of code with either will prevent the execution of that code in the script.

REM This is a comment
'This is also a comment
Response.Write "Hello"

Comments in JScript also come in two flavours, there is // for single-line comments and /* */ to span multiple lines.

// This is a comment
/*
This is also a comment
*/
response.write("Hello");

Useful Links

  • Commenting code in ASP Classic
like image 63
user692942 Avatar answered Jul 05 '26 11:07

user692942



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!