ASP variable declaration bug or feature?!

H

Huy Hoang

I tried to find something about this bug (or is it really a feature?),
but couldn't find anything in this group.

Here's the thing, I have the following code:

<%
option explicit
x = "hello world"
Response.Write(x)
Response.End
%>

Which of course will generate an error because variable 'x' is not
defined,
but take a look at the following code:

<%
option explicit
x = "hello world"
Response.Write(x)
Response.End
dim x
%>

You would think this will generate an error because logically-wise you
cannot refer to a variable before it is declared. But try the code
yourself, there will be no error generated.

Let's try the same with arrays:

<%
option explicit
x(0) = "hello "
x(1) = "world"
Response.Write(x(0) & x(1))
Response.End
%>

Of course, the code snippet above causes an error because just like the
first code snippet,
variable 'x' is not defined.

<%
option explicit
x(0) = "hello "
x(1) = "world"
Response.Write(x(0) & x(1))
Response.End
dim x(2)
%>

Now we declare 'x' as an array, but when running this code, ASP clearly
does not like it and returns a Type Mismatch error.

So is this a known bug or do I just have an old version of IIS?
 
B

Bob Barrows [MVP]

Huy said:
I tried to find something about this bug (or is it really a feature?),
but couldn't find anything in this group.

Here's the thing, I have the following code:

<%
option explicit
x = "hello world"
Response.Write(x)
Response.End
%>

Which of course will generate an error because variable 'x' is not
defined,
but take a look at the following code:

<%
option explicit
x = "hello world"
Response.Write(x)
Response.End
dim x
%>
It's vbscript, not ASP. This will occur with a .vbs file.
It's a known feature:
http://blogs.msdn.com/ericlippert/archive/2004/06/18/159378.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top