
redundant New: Dim rs As New ADODB.Recordset
Hi Tom,
You are mistaken on the order of creates a new instance of cmd.
1: Dim cmd As New ADODB.Command
2: Set cmd = Nothing
3: Debug.Print TypeName( cmd) 'Displays "Command"
Line 2: VB creates a new instance of Command object and immediately
destroys it.
Line 3: Creates a new instans of Command
You are absolutelly right of "decisions based..."
Thanks
Zsolt
Quote:
> Another more subtle side effect:
> Dim cmd As New ADODB.Command
> Set cmd = Nothing
> After cmd is set to nothing, VB immediately creates a new instance of cmd.
> Maybe not a big deal here, but if you have code that makes decisions based
> upon whether or not an object exists, you get into big trouble.
> - Tom
> > Well actually Dim cmd as new adodb.command is slower!
> > What you are actually saying is .......
> > If cmd = nothing then set cmd = new adodb.command
> > You should aways use..........
> > Dim cmd as Adodb.command
> > Set cmd = new adodb.command
> > Phrase from "ADO examples and best practices"
> > If you follow this best-pratice coding convention then
> > your applications will run a little faster, and you avoid crippling
> > some of the features provided by ADO when working with multiple
> > recordset stored procedures..............
> > So all I can say is what the other 2 advise is incorrect.........
> > Regards
> > VOrtex
> > > Hi,
> > > What do you think?
> > > --------------------------------------------------------
> > > Redundant use of New:
> > > ------------------------
> > > Dim cmd As New ADODB.Command
> > > Dim rs As New ADODB.Recordset 'redundant New
> > > ...
> > > Set rs = cmd.Execute 'for this
> > > ...
> > > rs.Close
> > > --------------------------------------------------------
> > > This is Ok:
> > > -----------
> > > Dim rs As New ADODB.Recordset
> > > rs.Open "SELECT * FROM Authors", "DSN=AdoDemo;UID=ad;PWD=;"
> > > ...
> > > rs.Close
> > > Set rs = Nothing
> > > --------------------------------------------------------
> > > Thanks in advance
> > > Zsolt