473,671 Members | 2,550 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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=CreateO bject("ADODB.CO NNECTION")
'ConnectionStri ng

Dim strSQL
strSQL="SELECT. ...FROM....WHER E....ORDER BY...."

Dim objRS
Set objRS=CreateObj ect("ADODB.RECO RDSET")
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 2866
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********@red iffmail.com> wrote in message
news:ux******** ******@TK2MSFTN GP12.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=CreateO bject("ADODB.CO NNECTION")
'ConnectionStri ng

Dim strSQL
strSQL="SELECT. ...FROM....WHER E....ORDER BY...."

Dim objRS
Set objRS=CreateObj ect("ADODB.RECO RDSET")
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=CreateO bject("ADODB.CO NNECTION")
'ConnectionStri ng

strSQL="SELECT. ...FROM....WHER E....ORDER BY...."

Set objRS=CreateObj ect("ADODB.RECO RDSET")
objRS.Open strSQL,objConn

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

HTH-Jon

"Arpan De" <ar********@red iffmail.com> wrote in message
news:ux******** ******@TK2MSFTN GP12.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=CreateO bject("ADODB.CO NNECTION")
'ConnectionStri ng

Dim strSQL
strSQL="SELECT. ...FROM....WHER E....ORDER BY...."

Dim objRS
Set objRS=CreateObj ect("ADODB.RECO RDSET")
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
4752
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
3189
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
6481
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 C. It can cause very ugly errors,like this: epsilon=0 S=0 while epsilon<10: S=S+epsilon
32
3807
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
7861
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 means that if I misspell a variable name, my program will mysteriously fail to work with no error message. If you don't declare variables, you can inadvertently re-use an variable used in an enclosing context when you don't intend to, or
7
2162
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 got is a decodeImage.aspx page that gets called to decode base64 encoded images and return them as displayable images to a Web page. The ASPX page is passed two parameters, "file" and "img". The "file" parameter specifies and XML file on the Web...
1
1023
by: Paul Aspinall | last post by:
Hi Is there a way of Preventing DropDownList from Dimming when disabled?? Thanks
6
1571
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 to read when they are disabled . Thanks, Bill Cincinnati, OH USA
4
1543
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
8483
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8927
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8825
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8676
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7445
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6237
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4416
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2819
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2062
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.