Close CreateObject()?

J

Jack Leach

I'm using some code to return an array of file properties:

With CreateObject("Shell.Application").NameSpace...

I'm wondering if it needs to be closed/destroyed somehow after I'm done with
it, as one would with an object? This is a new territory for me.

Thanks,



(the code, which seems to works well...)

Public Function TestProps() As String
Dim ret As Variant
ret = FileGetProperties("D:\something.jpg")
TestProps = ret(2)
End Function


'==============================================================================
' FileGetProperties
'
' Adapted (copied) from Michael Pierron
' http://www.pcreview.co.uk/forums/thread-1862574.php
'-----------------------
Public Function FileGetProperties(sfile As String) As Variant
On Error GoTo Err_Proc
Dim ret(34) As String
'==================
Dim i As Integer
Dim T As String
'==================

With CreateObject("Shell.Application").Namespace(Left( _
sfile, lPosition(sfile, "\") - 1))

For i = 0 To 34
T = .GetDetailsOf(.parsename(Dir(sfile)), i)
If Len(T) Then
ret(i) = .GetDetailsOf(.Items, i) & ":" & T
Debug.Print ret(i)
End If

Next i

End With

'==================
Exit_Proc:
FileGetProperties = ret
Exit Function
Err_Proc:
If cSYSDISPERR Then MsgBox "Error!" & vbCrLf & _
Str(Err.Number) & ": " & Err.Description, _
vbCritical, "Library Error!"
Resume Exit_Proc
Resume
End Function


Private Function lPosition%(Chain$, Char$)
'Dependant of FileGetProperties
Dim iPos%
Do
iPos = InStr(lPosition + 1, Chain, Char, 1)
If iPos Then lPosition = iPos Else Exit Do
Loop
End Function



--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
J

Jack Leach

How would I go about closing it in this context? Where does this object
reside and what would be the syntax for getting rid of it? Thanks.


With CreateObject("Shell.Application").Namespace(Left( _
sfile, lPosition(sfile, "\") - 1))
For i = 0 To 34
T = .GetDetailsOf(.parsename(Dir(sfile)), i)
If Len(T) Then
ret(i) = .GetDetailsOf(.Items, i) & ":" & T
Debug.Print ret(i)
End If
Next i
End With

--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
A

Alex Dybenko

Hi,
I think you can do like this:
dim oShell as object

set oShell=CreateObject("Shell.Application").Namespace(Left( _
sfile, lPosition(sfile, "\") - 1))
With oShell
For i = 0 To 34
T = .GetDetailsOf(.parsename(Dir(sfile)), i)
If Len(T) Then
ret(i) = .GetDetailsOf(.Items, i) & ":" & T
Debug.Print ret(i)
End If
Next I
.close (in case object has close method, could be also .Dispose method)
End With
set oShell=nothing

--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top