Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FileSystemObject close method 2

Status
Not open for further replies.

TempestT37

Programmer
May 19, 2003
15
0
0
US
Hello group
Is there any difference between the two lines below?
Which is better to use?

fso.Close()
Set fso = Nothing

Thank Michael
 
both should be used
first one (set = nothing) refers to the object that you created
the second refers to the file opened in which you need to close

so psuedo is
Set object = Nothing

File (TextSteam).Close


____________________________________________________
[sub]get the best answer to your questions by asking the best questions "General FAQ" faq333-2924[/sub]
onpnt2.gif
[sub][sup][/sup][/sub]
 
I keep getting “Object required” .
Can you see what I am doing wrong?


<%
fileName = Request(&quot;fileName&quot;)
Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set fileObject = fso.GetFile(&quot;d:\webs\cent44\data\&quot;& fileName &&quot;&quot;)
Set textStreamObject = fileObject.OpenAsTextStream(1,0)
newInfo = textStreamObject.ReadAll
Set textStreamObject = Nothing
'textStreamObject.Close
Set fileObject = Nothing
'fileObject.Close
fso.DeleteFile(&quot;d:\webs\cent44\data\&quot;& fileName &&quot;&quot;)
Set fso = Nothing
fso.Close %>
 
You need to .Close it before you set it to Nothing.

--James
 
The only one that need to worry about is textStreamObject, right? I hope so when I try the other two (fileObject and fso) I get errors.

Michael

textStreamObject.Close
Set textStreamObject = Nothing
'fileObject.Close
Set fileObject = Nothing
fso.DeleteFile(&quot;d:\webs\cent44\data\&quot;& fileName &&quot;&quot;)
'fso.Close
Set fso = Nothing
 
Yes. Any variable that is Set to an object instance should always be set to Nothing at the end.

Additionally, if an object has been .Opened then you should .Close it as well.

--James
 
recommended to close it before setting it to nothing, because you cant close it after the object has been destroyed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top