Hi Tony,
Since you're talking about destroying files by setting to nothing, I had a
related question on another thread.
if I were to open a file thus
sResult=
CreateObject("Scripting.FileSystemObject").OpenTextFile(fname).ReadAll
does that open file handle get closed when the sub terminates and sResult
goes out of scope? or maybe even immediatly after .Readall???
or is there somehow a transient bit of memory floating around that still has
the file open? also curious about the fso object that was created, since
theres no variable pointing to it, how and when is it released? magically
and instantly as soon as it's done it's work?
it doesn't put a lock on the file so there's no problem with subsequently
opening it in for example, notepad, but i was just curious about a second
opinion.
"Tony Tanzillo" wrote in message
news:DD6601BF9312A0A9DCC34B59971E34F3@in.WebX.maYIadrTaRb...
> "Dave F" wrote in message
news:1789035C898EEE36465216489561B600@in.WebX.maYIadrTaRb...
> > Hi
> >
> > I understand what Nothing does:
> >
> > Set MyObject = Nothing
> >
> > But I don't understand the reason for it.
> > Especially at the end of a routine
> >
> > Doesn't End Sub do the same thing?
>
> Yes, and doing it explicitly is entirely pointless.
>
> The only time that you need to explicitly set a
> local object variable to Nothing, is if the code
> that follows depends on a side-effect of the object
> destroying itself, or when you want to control the
> order in which multiple, interdependent objects are
> destroyed.
>
> A good example of this would be an ObjectDBX document
> which you need to move/rename after accessing it via
> ObjectDBX. Since the only way to release the lock on
> the .DWG file is by destroying the AxDbDocument object,
> if you wanted to rename the .DWG file after you've
> finished accessing it, you would first have to set the
> AxDbDocument variable to Nothing, to release the lock
> on the file.
>
> --
> AcadXTabs: Document Tabs for AutoCAD
> http://www.acadxtabs.com
>
>
>