Name Redefined

Discussion in 'ASP General' started by James, Apr 12, 2005.

  1. James

    James Guest

    Should be a simple question...not sure why this ISN'T having a problem:

    For x = 1 to 5
    Dim y
    Next

    Shouldn't that fire a "Name Redefined" error the way this does:

    For x = 1 to 5
    Dim y
    Next

    Dim y
    James, Apr 12, 2005
    #1
    1. Advertising

  2. The parser is pretty stupid. In the second case, it reads through the code
    (without executing the loop) and sees two identical Dim statements. It has
    nothing to do with how many times the statement is actually executed; only
    with how many times it appears.

    --
    This is my signature. It is a general reminder.
    Please post DDL, sample data and desired results.
    See http://www.aspfaq.com/5006 for info.

    "James" <> wrote in message
    news:%...
    > Should be a simple question...not sure why this ISN'T having a problem:
    >
    > For x = 1 to 5
    > Dim y
    > Next
    >
    > Shouldn't that fire a "Name Redefined" error the way this does:
    >
    > For x = 1 to 5
    > Dim y
    > Next
    >
    > Dim y
    >
    >
    Aaron [SQL Server MVP], Apr 12, 2005
    #2
    1. Advertising

  3. James

    James Guest

    Makes sense...just wanted to make sure I wasn't missing anything. Thanks.

    "Aaron [SQL Server MVP]" <> wrote in message
    news:%23WkG$...
    > The parser is pretty stupid. In the second case, it reads through the

    code
    > (without executing the loop) and sees two identical Dim statements. It

    has
    > nothing to do with how many times the statement is actually executed; only
    > with how many times it appears.
    >
    > --
    > This is my signature. It is a general reminder.
    > Please post DDL, sample data and desired results.
    > See http://www.aspfaq.com/5006 for info.
    >
    > "James" <> wrote in message
    > news:%...
    > > Should be a simple question...not sure why this ISN'T having a problem:
    > >
    > > For x = 1 to 5
    > > Dim y
    > > Next
    > >
    > > Shouldn't that fire a "Name Redefined" error the way this does:
    > >
    > > For x = 1 to 5
    > > Dim y
    > > Next
    > >
    > > Dim y
    > >
    > >

    >
    >
    James, Apr 12, 2005
    #3
  4. Now that you have your answer, may I ask if you are really planning on
    dimming something in a loop like this? Or were you just playing around
    trying to get an error?

    Ray at work

    "James" <> wrote in message
    news:%...
    > Should be a simple question...not sure why this ISN'T having a problem:
    >
    > For x = 1 to 5
    > Dim y
    > Next
    >
    > Shouldn't that fire a "Name Redefined" error the way this does:
    >
    > For x = 1 to 5
    > Dim y
    > Next
    >
    > Dim y
    >
    >
    Ray Costanzo [MVP], Apr 12, 2005
    #4
  5. James

    James Guest

    LOL, no...I don't intend to design something like this. Long story short,
    I have an ENORMOUS page built by someone else in our company that's long
    since departed. From a bare glance at the page, I knew where I needed to
    put my add on, but I wasn't sure if I was inside any kind of a loop. The
    code is horribly indented/commented. Curiousity sparked my example. I
    ended up having to document/format the page anyway. I wasn't intending to
    proceed without knowing exactly what was going on anyway. Just curiousity
    =).

    "Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
    message news:...
    > Now that you have your answer, may I ask if you are really planning on
    > dimming something in a loop like this? Or were you just playing around
    > trying to get an error?
    >
    > Ray at work
    >
    > "James" <> wrote in message
    > news:%...
    > > Should be a simple question...not sure why this ISN'T having a problem:
    > >
    > > For x = 1 to 5
    > > Dim y
    > > Next
    > >
    > > Shouldn't that fire a "Name Redefined" error the way this does:
    > >
    > > For x = 1 to 5
    > > Dim y
    > > Next
    > >
    > > Dim y
    > >
    > >

    >
    >
    James, Apr 12, 2005
    #5
  6. On Tue, 12 Apr 2005 13:06:24 -0400, "Ray Costanzo [MVP]" <my first name
    at lane 34 dot commercial> wrote:
    in <>

    >Now that you have your answer, may I ask if you are really planning on
    >dimming something in a loop like this? Or were you just playing around
    >trying to get an error?
    >
    >Ray at work


    It makes no matter where your Dims appear as long as they precede any
    reference to the variable. I put all my Dims right where the variable
    is used the first time which makes for more readable code IMHO.


    ---
    Stefan Berglund
    Stefan Berglund, Apr 13, 2005
    #6
  7. James

    Mark Schupp Guest

    IIRC it doesn't matter where you put your dims as long as they are in the
    same scope as the variable reference. Try this.

    <%@ Language=VBScript %>
    <%

    data = "here I am"

    dim data

    Response.Write data
    %>

    --
    --Mark Schupp
    Head of Development
    Integrity eLearning
    www.ielearning.com


    "Stefan Berglund" <> wrote in message
    news:...
    > On Tue, 12 Apr 2005 13:06:24 -0400, "Ray Costanzo [MVP]" <my first name
    > at lane 34 dot commercial> wrote:
    > in <>
    >
    >>Now that you have your answer, may I ask if you are really planning on
    >>dimming something in a loop like this? Or were you just playing around
    >>trying to get an error?
    >>
    >>Ray at work

    >
    > It makes no matter where your Dims appear as long as they precede any
    > reference to the variable. I put all my Dims right where the variable
    > is used the first time which makes for more readable code IMHO.
    >
    >
    > ---
    > Stefan Berglund
    Mark Schupp, Apr 13, 2005
    #7
  8. On Wed, 13 Apr 2005 09:33:22 -0700, "Mark Schupp" <>
    wrote:
    in <>

    >IIRC it doesn't matter where you put your dims as long as they are in the
    >same scope as the variable reference. Try this.
    >
    ><%@ Language=VBScript %>
    ><%
    >
    >data = "here I am"
    >
    >dim data
    >
    >Response.Write data
    >%>


    Interesting. VBScript is more forgiving than VB6.


    ---
    Stefan Berglund
    Stefan Berglund, Apr 14, 2005
    #8
    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. Replies:
    1
    Views:
    623
    Victor Bazarov
    Apr 1, 2005
  2. Wei Li

    function redefined problem

    Wei Li, Aug 25, 2004, in forum: C Programming
    Replies:
    11
    Views:
    689
    Wei Li
    Aug 27, 2004
  3. irfanhab
    Replies:
    1
    Views:
    458
    Nick Keighley
    Aug 23, 2006
  4. DaveF

    dim Name redefined error

    DaveF, Apr 14, 2004, in forum: ASP General
    Replies:
    8
    Views:
    622
    Aaron Bertrand [MVP]
    Apr 14, 2004
  5. MiG
    Replies:
    8
    Views:
    135
    Ryan Leavengood
    Oct 19, 2005
Loading...

Share This Page