473,408 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Dimming A Variable More Than Once

Suppose I have the following ASP code:

<%
Dim strName
.....................
.....................
.....................
.....................
.....................
.....................
Dim strName
%>

The above code will throw an error saying Name redefined pointing to the second Dim strName. That's OK but why isn't the same
error thrown in the following case?

<%
Dim objConn
Set objConn=CreateObject("ADODB.CONNECTION")
'ConnectionString

Dim strSQL
strSQL="SELECT....FROM....WHERE....ORDER BY...."

Dim objRS
Set objRS=CreateObject("ADODB.RECORDSET")
objRS.Open strSQL,objConn

Do Until(objRS.EOF)
Dim strName
strName=objRS("Name")
..........................
..........................
..........................
..........................
..........................
objRS.MoveNext
Loop
%>

In the 2nd code snippet, the variable strName is Dim(med) for the 1st DB record. When the cursor comes to the 2nd record, again
strName is Dim(med). strName is yet again Dim(med) when the cursor comes to the 3rd record so on & so forth. So why isn't the Name
redefined error being thrown here? Isn't the variable strName getting Dim(med) here more than once in the same way as the variable
strName is Dim(med) more than once in the 1st code snippet? Is the variable strName destroyed & recreated after each record in the
2nd code snippet?

Thanks,

Arpan
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.502 / Virus Database: 300 - Release Date: 18/07/2003
Jul 19 '05 #1
2 2852
Think of it, conceptually, like this:

Do Until(objRS.EOF)
PrintName(objRS)
objRS.MoveNext
Loop

Private Function PrintName(objRS)
Dim strName
stName = objRS("name")

Response.Write(strName)

End Function

When you call each iteration of the loop, it is as if you were calling a
function and declaring the variable again.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
Author: ADO.NET and XML: ASP.NET on the Edge

************************************************** **************************
****
Think Outside the Box!
************************************************** **************************
****
"Arpan De" <ar********@rediffmail.com> wrote in message
news:ux**************@TK2MSFTNGP12.phx.gbl...
Suppose I have the following ASP code:

<%
Dim strName
.....................
.....................
.....................
.....................
.....................
.....................
Dim strName
%>

The above code will throw an error saying Name redefined pointing to the second Dim strName. That's OK but why isn't the same error thrown in the following case?

<%
Dim objConn
Set objConn=CreateObject("ADODB.CONNECTION")
'ConnectionString

Dim strSQL
strSQL="SELECT....FROM....WHERE....ORDER BY...."

Dim objRS
Set objRS=CreateObject("ADODB.RECORDSET")
objRS.Open strSQL,objConn

Do Until(objRS.EOF)
Dim strName
strName=objRS("Name")
..........................
..........................
..........................
..........................
..........................
objRS.MoveNext
Loop
%>

In the 2nd code snippet, the variable strName is Dim(med) for the 1st DB record. When the cursor comes to the 2nd record, again strName is Dim(med). strName is yet again Dim(med) when the cursor comes to the 3rd record so on & so forth. So why isn't the Name redefined error being thrown here? Isn't the variable strName getting Dim(med) here more than once in the same way as the variable strName is Dim(med) more than once in the 1st code snippet? Is the variable strName destroyed & recreated after each record in the 2nd code snippet?

Thanks,

Arpan
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.502 / Virus Database: 300 - Release Date: 18/07/2003

Jul 19 '05 #2
Dim is not a run time statement, it is compile time. ASP essentially treats
all Dim statements as if they are at the top of their context (procedure vs.
module). So, in your example, this is what ASP "sees":

<%
Dim objConn
Dim strSQL
Dim objRS
Dim strName

Set objConn=CreateObject("ADODB.CONNECTION")
'ConnectionString

strSQL="SELECT....FROM....WHERE....ORDER BY...."

Set objRS=CreateObject("ADODB.RECORDSET")
objRS.Open strSQL,objConn

Do Until(objRS.EOF)
strName=objRS("Name")
..........................
..........................
..........................
..........................
..........................
objRS.MoveNext
Loop
%>

HTH-Jon

"Arpan De" <ar********@rediffmail.com> wrote in message
news:ux**************@TK2MSFTNGP12.phx.gbl...
Suppose I have the following ASP code:

<%
Dim strName
.....................
.....................
.....................
.....................
.....................
.....................
Dim strName
%>

The above code will throw an error saying Name redefined pointing to the second Dim strName. That's OK but why isn't the same error thrown in the following case?

<%
Dim objConn
Set objConn=CreateObject("ADODB.CONNECTION")
'ConnectionString

Dim strSQL
strSQL="SELECT....FROM....WHERE....ORDER BY...."

Dim objRS
Set objRS=CreateObject("ADODB.RECORDSET")
objRS.Open strSQL,objConn

Do Until(objRS.EOF)
Dim strName
strName=objRS("Name")
..........................
..........................
..........................
..........................
..........................
objRS.MoveNext
Loop
%>

In the 2nd code snippet, the variable strName is Dim(med) for the 1st DB record. When the cursor comes to the 2nd record, again strName is Dim(med). strName is yet again Dim(med) when the cursor comes to the 3rd record so on & so forth. So why isn't the Name redefined error being thrown here? Isn't the variable strName getting Dim(med) here more than once in the same way as the variable strName is Dim(med) more than once in the 1st code snippet? Is the variable strName destroyed & recreated after each record in the 2nd code snippet?

Thanks,

Arpan
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.502 / Virus Database: 300 - Release Date: 18/07/2003

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Google Mike | last post by:
Is there such a thing as ASP's Option Explicit in PHP, where I require variable declarations? This prevents typos and I find it useful at least for me.
6
by: Brian Jones | last post by:
I'm sure the solution may be obvious, but this problem is driving me mad. The following is my code: class a(object): mastervar = def __init__(self): print 'called a'
83
by: Alexander Zatvornitskiy | last post by:
Hello All! I'am novice in python, and I find one very bad thing (from my point of view) in language. There is no keyword or syntax to declare variable, like 'var' in Pascal, or special syntax in...
32
by: Wenjie | last post by:
Hello, We had a code review with the argument of whether "i" is out of scope as illustrated below: for (int i=0; i<2004; i++) { doSomething(i); }
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
7
by: Greg Collins [MVP] | last post by:
Hi, I couldn't find what I was looking for by searching the newsgroup, but perhaps these have already been discussed somewhere. This is a bit long with a lot of interrelated questions. What I've...
1
by: Paul Aspinall | last post by:
Hi Is there a way of Preventing DropDownList from Dimming when disabled?? Thanks
6
by: namewitheldbyrequest | last post by:
Is there a way to disable a web form control (change the Enabled property to false) without the control being dimmed out when it's rendered? I have quite a few of them on the form and they are hard...
4
by: Just Me | last post by:
Ive noticed that web sites are emulating the vista screen dimming when the relevent control comes into focus like sliding div forms etc. Does anyone know how that is acheived ? Cheers
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.