Name Redefined

J

James

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
 
A

Aaron [SQL Server MVP]

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.
 
R

Ray Costanzo [MVP]

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
 
J

James

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
=).
 
S

Stefan Berglund

in said:
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.
 
M

Mark Schupp

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
%>
 
S

Stefan Berglund

in said:
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.
 

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

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top