473,398 Members | 2,088 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,398 software developers and data experts.

Forgive me!

A dumb friday-afternoon-and-I-need-a-weekend question.

I inherited an application that has code similar to:

set conn = server.CreateObject("ADODB.Connection")
set New_app = server.CreateObject("ADODB.Recordset")
set New_app = conn.Execute("SELECT * FROM TableName WHERE Blah = '"&
blah & "'")

The code executes a "set New_app" instruction TWO TIMES. Doesn't the
second "set New_app" instruction override the first "set New_app"
instruction?

And is it correct that the
set New_app = server.CreateObject("ADODB.Recordset")
instruction is totally unnecessary anyway?

Thanks
Jul 19 '05 #1
8 1927
CJM
First of all, 'dumb' questions are inevitable sometimes, so you dont need
the 'Forgive Me'
Second, it helps the rest of us figure out what kind of dumb question you
are asking if you give a more meaningful Subject line.
Thirdly, it's not really much of a dumb question at all.

Given this example, you don't need to declare New_app as a recordset, but
you are entitled to. There are times where it is useful/necessary, e.g if
you explicitly declare a variable as a recordset, intellisense can then list
the properties and methods for you.

Yes, this runs the 'Set New_app' code twice but it is doing two different
things:
- The first line states that you want New_app to hold an empty recordset.
- The conn.Execute in the second line returns a recordset that is then
stored in New_app.

In this example you *can* miss out the first Set statement.

There are other techniques and styles in common use, in which case declare a
variable explicitly in this way is needed.

hth

Chris

"Luis" <an****@webmail.co.za> wrote in message
news:69**************************@posting.google.c om...
A dumb friday-afternoon-and-I-need-a-weekend question.

I inherited an application that has code similar to:

set conn = server.CreateObject("ADODB.Connection")
set New_app = server.CreateObject("ADODB.Recordset")
set New_app = conn.Execute("SELECT * FROM TableName WHERE Blah = '"&
blah & "'")

The code executes a "set New_app" instruction TWO TIMES. Doesn't the
second "set New_app" instruction override the first "set New_app"
instruction?

And is it correct that the
set New_app = server.CreateObject("ADODB.Recordset")
instruction is totally unnecessary anyway?

Thanks

Jul 19 '05 #2
Looks like the original developer wanted the intellisense feature to
kick-off for the New_App object - it only happens if you do an explicit
CreateObject(ProgID) call (at least in Interdev).

In terms of code execution the speed diff will be negligible (don't ask me
to define 'negligible' please). The second call is just modifying the
pointer and letting the previous object destroy itself.

I use that construct a lot where I'm getting objects passed back from other
objects (especially for my own DLL based components) since Interdev then
helps me with my own DLL method calls. I know it's not the most efficient
but it does help to stop me from making stupid method call mistakes.

Chris.

"Luis" <an****@webmail.co.za> wrote in message
news:69**************************@posting.google.c om...
A dumb friday-afternoon-and-I-need-a-weekend question.

I inherited an application that has code similar to:

set conn = server.CreateObject("ADODB.Connection")
set New_app = server.CreateObject("ADODB.Recordset")
set New_app = conn.Execute("SELECT * FROM TableName WHERE Blah = '"&
blah & "'")

The code executes a "set New_app" instruction TWO TIMES. Doesn't the
second "set New_app" instruction override the first "set New_app"
instruction?

And is it correct that the
set New_app = server.CreateObject("ADODB.Recordset")
instruction is totally unnecessary anyway?

Thanks
Jul 19 '05 #3
"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> schrieb im Newsbeitrag
news:et**************@TK2MSFTNGP12.phx.gbl...
I use that construct a lot where I'm getting objects passed back from other objects (especially for my own DLL based components) since Interdev then
helps me with my own DLL method calls. I know it's not the most efficient
but it does help to stop me from making stupid method call mistakes.


I do also use this feature for making Intellisense work. What I found out,
is the following: the statement with the CreateObject assignment does not
have to be executed, it does not even have to be reachable. For example my
ASP-pages always contain code like:

<%
' here is the real code

Sub DummyNeverToBeExecuted()
Dim rs
Set rs = CreateObject("ADODB.Recordset")
' and many more assignments with typical variable names
End Sub
%>

Any occurence of the variable rs in the "real code" will then offer
intellisense.

Michael G. Schneider
Jul 19 '05 #4
Yeah, I also found that.

It also screws up if you have two same named object variables in different
subs (eg. diff scope) using different ProgID's!

Thats a pain in the butt when doing class based VBScript against DLL stuff.

Chris.

"Michael G. Schneider" <mg*@mgs-software.de> wrote in message
news:O$**************@TK2MSFTNGP10.phx.gbl...
"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> schrieb im Newsbeitrag
news:et**************@TK2MSFTNGP12.phx.gbl...
I use that construct a lot where I'm getting objects passed back from other objects (especially for my own DLL based components) since Interdev then
helps me with my own DLL method calls. I know it's not the most efficient
but it does help to stop me from making stupid method call mistakes.


I do also use this feature for making Intellisense work. What I found out,
is the following: the statement with the CreateObject assignment does not
have to be executed, it does not even have to be reachable. For example my
ASP-pages always contain code like:

<%
' here is the real code

Sub DummyNeverToBeExecuted()
Dim rs
Set rs = CreateObject("ADODB.Recordset")
' and many more assignments with typical variable names
End Sub
%>

Any occurence of the variable rs in the "real code" will then offer
intellisense.

Michael G. Schneider

Jul 19 '05 #5
CJM
While I wouldn't use your approach, I guess I've borrowed the same idea:

Sometimes, if I can't remember the right properties methods, I'll use the
CreateObject line to prompt Intellisense, then remove it when I have
finished the bulk of my coding...

Chris

"Michael G. Schneider" <mg*@mgs-software.de> wrote in message
news:O$**************@TK2MSFTNGP10.phx.gbl...
I do also use this feature for making Intellisense work. What I found out,
is the following: the statement with the CreateObject assignment does not
have to be executed, it does not even have to be reachable. For example my
ASP-pages always contain code like:

<%
' here is the real code

Sub DummyNeverToBeExecuted()
Dim rs
Set rs = CreateObject("ADODB.Recordset")
' and many more assignments with typical variable names
End Sub
%>

Any occurence of the variable rs in the "real code" will then offer
intellisense.

Michael G. Schneider

Jul 19 '05 #6
"CJM" <cj*****@yahoo.co.uk> schrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP12.phx.gbl...
While I wouldn't use your approach, I guess I've borrowed the same idea:


Why wouldn't you use the approach? Does it have any disadvantages, I am not
aware of?

Michael G. Schneider
Jul 19 '05 #7
Yikes, an argument about Interdev?
It's a pile of poo in some respects and amazing in others.

Do what you are comfortable with and find workarounds for the rest is my
motto. As long as the code looks good, is maintainable, efficient, well
documented, reusable (oh damn, I was talking about VB again).

LoL.

Chris.

"Michael G. Schneider" <mg*@mgs-software.de> wrote in message
news:OD**************@TK2MSFTNGP12.phx.gbl...
"CJM" <cj*****@yahoo.co.uk> schrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP12.phx.gbl...
While I wouldn't use your approach, I guess I've borrowed the same idea:


Why wouldn't you use the approach? Does it have any disadvantages, I am not
aware of?

Michael G. Schneider

Jul 19 '05 #8
CJM
I meant 'I wouldnt use this approach', as opposed to 'One shouldn't use this
approach'...

I don't know if there is any overhead with your solution, but if there is I
imagine it's minimal. But personally I'd prefer not to leave code in their
that doesnt do anything. Like I said b4, I put the declaration in to
stimulate intellisense, but take it out when finished.

Cheers

Chris
"Michael G. Schneider" <mg*@mgs-software.de> wrote in message
news:OD**************@TK2MSFTNGP12.phx.gbl...
"CJM" <cj*****@yahoo.co.uk> schrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP12.phx.gbl...
While I wouldn't use your approach, I guess I've borrowed the same idea:
Why wouldn't you use the approach? Does it have any disadvantages, I am

not aware of?

Michael G. Schneider

Jul 19 '05 #9

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

Similar topics

3
by: TheFerryman | last post by:
Which is the microsoft MSVC6 newsgroup? I've been searching for half an hour and I cannot find it.
7
by: irecruit | last post by:
Hi All, Forgive me for not positing on a .jobs news group but I thought that the position in question was/is relevant to the group. I Looking for a C programmer with customer interfacing...
4
by: Bill Dodd | last post by:
Is there really no way to have different asp.net applications share session variables? The problem I'm running into is that I have numerous asp.net (and asp) applications that were written as...
2
by: Bob Graham | last post by:
When my applications hit certain types of errors, it shows me a box that says if I enable JIT debugging in the machine.config file, the code will break into a debugger instead of showing me the...
16
by: IAmIronMan | last post by:
I apologize for being rude and not considerate of others here. Scorpion53061 please reply to let me know you forgive me. You claim to be a Christian so you should be willing to forgive me.
29
by: Geoff Jones | last post by:
Hi All I hope you'll forgive me for posting this here (I've also posted to ado site but with no response so far) as I'm urgently after a solution. Can anybody help me? I'm updating a table on...
5
by: James Woody | last post by:
Hello friends. I would like to pull the value of one field from a local database and display it on a page. I spent an hour looking for the solution. I feel that is more than enough dues to pay...
1
by: msdn | last post by:
I know this is not a JavaScript group. Direct me to the right place if you get offended Question: Does anyone know exactly what does code below mean or do. var AZ = Function.AZ =...
3
by: hackyk | last post by:
Hey I would like to know how i cud write classes that would implement its own methods so wen i us them I do not have to write the code in the main program.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
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,...
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
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
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...
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.