Re: How to determine if object (recordset) is set?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Michael Thompson (thommo_at_pobox.com)
Date: 06/23/04


Date: Tue, 22 Jun 2004 23:40:52 -0700


Mark, you are not entirely correct that comparing an object to nothing
does not alter the object. It depends on how the object is declared.
Consider the following:

dim rs as new adodb.recordset

set rs = nothing 'rs is already nothing, but it can't hurt

if rs is nothing then
  debug.print "rs is nothing"
else
  debug.print "rs is NOT nothing"
endif

And surprise surprise the output is "rs is NOT nothing". Why? Because
the variable was declared "rs as NEW adodb.recordset". This causes every
reference to rs to check if it is currently nothing and if so, go off
and create one.

Bottom line is that the "as new" syntax for declaring an object variable
should NEVER be used. It is inefficient and totally unnecessary.

Mike.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!



Relevant Pages

  • Re: c# - Interlocked.Exchange and value types
    ... for comparing and assigning enum values? ... Declaring the variable as ... volatile should do the job, if I read the docs correctly. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: program bug
    ... This is comparing the address ... of first program argument to the address of the string literal "b" ... Was declaring b as a pointer to char proper? ...
    (comp.lang.c)
  • Re: Variable declaration - C vs script style
    ... when declaring variables within loops ... comparing to all forward declarations. ... I'm mostly writing up to a few ... If the limiting factor in your script ...
    (comp.lang.perl.misc)
  • Re: LPTSTR initialization
    ... > stupid for not declaring them const. ... But the function does alter the variable, ...
    (comp.lang.cpp)