ASP variable declaration bug or feature?!

Discussion in 'ASP General' started by Huy Hoang, Jan 5, 2006.

  1. Huy Hoang

    Huy Hoang Guest

    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?
     
    Huy Hoang, Jan 5, 2006
    #1
    1. Advertising

  2. Huy Hoang wrote:
    > 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
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Jan 5, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Noah
    Replies:
    5
    Views:
    962
  2. Alex Vinokur
    Replies:
    4
    Views:
    595
    Jonathan Turkanis
    Apr 5, 2004
  3. baumann@pan

    variable definiton / variable declaration

    baumann@pan, May 11, 2005, in forum: C Programming
    Replies:
    3
    Views:
    542
    CBFalconer
    May 11, 2005
  4. Bolin
    Replies:
    4
    Views:
    412
  5. robic0
    Replies:
    7
    Views:
    105
    Samwyse
    Jan 24, 2006
Loading...

Share This Page