Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 19th, 2005, 09:21 AM
Luis
Guest
 
Posts: n/a
Default 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
  #2  
Old July 19th, 2005, 09:21 AM
CJM
Guest
 
Posts: n/a
Default Re: Forgive me!

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" <andyza@webmail.co.za> wrote in message
news:69476b6f.0310310323.43950ed7@posting.google.c om...[color=blue]
> 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[/color]


  #3  
Old July 19th, 2005, 09:21 AM
Chris Barber
Guest
 
Posts: n/a
Default Re: Forgive me!

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" <andyza@webmail.co.za> wrote in message
news:69476b6f.0310310323.43950ed7@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


  #4  
Old July 19th, 2005, 09:21 AM
Michael G. Schneider
Guest
 
Posts: n/a
Default Re: Forgive me!

"Chris Barber" <chris@blue-canoe.co.uk.NOSPAM> schrieb im Newsbeitrag
news:etYgMy6nDHA.2772@TK2MSFTNGP12.phx.gbl...
[color=blue]
> I use that construct a lot where I'm getting objects passed back from[/color]
other[color=blue]
> 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.[/color]

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


  #5  
Old July 19th, 2005, 09:21 AM
Chris Barber
Guest
 
Posts: n/a
Default Re: Forgive me!

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" <mgs@mgs-software.de> wrote in message
news:O$GFVA7nDHA.2432@TK2MSFTNGP10.phx.gbl...
"Chris Barber" <chris@blue-canoe.co.uk.NOSPAM> schrieb im Newsbeitrag
news:etYgMy6nDHA.2772@TK2MSFTNGP12.phx.gbl...
[color=blue]
> I use that construct a lot where I'm getting objects passed back from[/color]
other[color=blue]
> 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.[/color]

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



  #6  
Old July 19th, 2005, 09:21 AM
CJM
Guest
 
Posts: n/a
Default Re: Forgive me!

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" <mgs@mgs-software.de> wrote in message
news:O$GFVA7nDHA.2432@TK2MSFTNGP10.phx.gbl...
[color=blue]
> 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
>
>[/color]


  #7  
Old July 19th, 2005, 09:21 AM
Michael G. Schneider
Guest
 
Posts: n/a
Default Re: Forgive me!

"CJM" <cjmwork@yahoo.co.uk> schrieb im Newsbeitrag
news:%23tPkxv7nDHA.2000@TK2MSFTNGP12.phx.gbl...
[color=blue]
> While I wouldn't use your approach, I guess I've borrowed the same idea:[/color]

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

Michael G. Schneider


  #8  
Old July 19th, 2005, 09:22 AM
Chris Barber
Guest
 
Posts: n/a
Default Re: Forgive me!

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" <mgs@mgs-software.de> wrote in message
news:ODu7Vl8nDHA.2012@TK2MSFTNGP12.phx.gbl...
"CJM" <cjmwork@yahoo.co.uk> schrieb im Newsbeitrag
news:%23tPkxv7nDHA.2000@TK2MSFTNGP12.phx.gbl...
[color=blue]
> While I wouldn't use your approach, I guess I've borrowed the same idea:[/color]

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

Michael G. Schneider



  #9  
Old July 19th, 2005, 09:23 AM
CJM
Guest
 
Posts: n/a
Default Re: Forgive me!

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" <mgs@mgs-software.de> wrote in message
news:ODu7Vl8nDHA.2012@TK2MSFTNGP12.phx.gbl...[color=blue]
> "CJM" <cjmwork@yahoo.co.uk> schrieb im Newsbeitrag
> news:%23tPkxv7nDHA.2000@TK2MSFTNGP12.phx.gbl...
>[color=green]
> > While I wouldn't use your approach, I guess I've borrowed the same idea:[/color]
>
> Why wouldn't you use the approach? Does it have any disadvantages, I am[/color]
not[color=blue]
> aware of?
>
> Michael G. Schneider
>
>[/color]


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles