Re: Difference betten New & ...
From: Ralph (msnews.20.nt_consulting32_at_spamgourmet.com)
Date: 01/19/05
- Next message: Harold Druss: "Tables relationships"
- Previous message: Jiju Joseph: "Difference betten New & ..."
- In reply to: Jiju Joseph: "Difference betten New & ..."
- Next in thread: Christoph Basedau: "Re: Difference betten New & ..."
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 19 Jan 2005 06:52:24 -0600
"Jiju Joseph" <JijuJoseph@discussions.microsoft.com> wrote in message
news:1C595B68-F79F-4F36-B763-9D375EE045ED@microsoft.com...
> Hi,
>
> Can anyone tell me the difference between,
> 1. Dim a as New ADODB.Connection &
> 2. Dim a as ADODB.Connection.
>
> Tell me a difference other than memory allocation.
"Dim a As New ADODB.Connection"
Both declares and defines (creates) a Connection Object which is referenced
thru the Reference Variable 'a'.
It always insures that 'a' will reference a connection object, even
recreating one if necessary.
It has though the rest of your code is coded like this whenever you refer to
'a'.
If IsNull(a) Then
Set a = New ADODB.Connection
End If
Debug.Print a.Version
This adds additional often un-needed code.
If you manually set 'a' to Nothing, then you will automatically get a new
connection.
ie, Set a = Nothing ' becomes
Set a = Nothing
Set a = New ADODB.Connection
Which offers an interesting opportunity for failure.
Using... Dim a As ADODB.Connection
...
Set a = New ADODB.Connection
...
Set a = Nothing
Provides greater lattitude for control and less opportunity to shoot
yourself in the foot. (Well when it does happen you have an easier time
finding out where and how to repair. <g>)
hth
-ralph
- Next message: Harold Druss: "Tables relationships"
- Previous message: Jiju Joseph: "Difference betten New & ..."
- In reply to: Jiju Joseph: "Difference betten New & ..."
- Next in thread: Christoph Basedau: "Re: Difference betten New & ..."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|