From: Alex Balfour on
In a freeware offering to which I'm adding a Currency Converter, I'm
downloading and unzipping a file of currency exchange rates from the
European Central Bank website each day. Everything is working fine on a
number of Windows 7 systems, both 32-bit and 64-bit, but produces
run-time error 430 (Class doesn't support Automation) on two different
Windows XP based PCs.

I've pinpointed the cause of the error message to the line:

Set ShellClass = New Shell32.Shell

in the following subprogram.

Public Sub UnZip(sFileSource As String, sFileDest As String, ErrorFlag
As Boolean)
' Unzips a zip file and puts its contents into a specified folder

Dim ShellClass As Shell32.Shell
Dim Filesource As Shell32.Folder
Dim Filedest As Shell32.Folder
Dim Folderitems As Shell32.Folderitems

On Error GoTo UZ_1
ErrorFlag = False
Set ShellClass = New Shell32.Shell
Set Filesource = ShellClass.NameSpace(sFileSource) ' should be zip file
Set Filedest = ShellClass.NameSpace(sFileDest) ' should be folder
Set Folderitems = Filesource.Items
Filedest.CopyHere Folderitems, 20

' Wait 1 second for separate thread

Sleep 1000

UZ_2:
Set ShellClass = Nothing
Set Filesource = Nothing
Set Filedest = Nothing
Set Folderitems = Nothing

Exit Sub
UZ_1: ErrCode = Err
ErrorFlag = True
ProcNum = 569
ErrorHandler ErrCode
Resume UZ_2
End Sub

Has anyone any thoughts or suggestions? The above code is based on that
given at:

http://www.vbforums.com/archive/index.php/t-534899.html

AlexB
From: Mayayana on
A couple of things:

Shell data types are funky. In some cases you'll
get unexpected errors if you use those types because
they're variant types that don't translate directly in
VB. I think FolderItems is one of those types. (You
can check it in the object browser.) Fortunately, you
can still use variants. Anyplace where it acts up, try
switching that data type to Object or reference it
directly rather than assigning it to an object. (I doubt
that the Shell object reference is the actual error.)

Why would you use a variable name FolderItems for
a FolderItems object?! That's asking for trouble.

Nevertheless, your code works fine for me on XP.
(Except that it shows a file-copy dialogue and seems
to extract twice from the zip, because it asks for
overwrite permission. You might be better off looking
for a different way to extract the ZIP file.)

Whatever the problem is I doubt very much that it's
coming from the Shell object initialization.

| In a freeware offering to which I'm adding a Currency Converter, I'm
| downloading and unzipping a file of currency exchange rates from the
| European Central Bank website each day. Everything is working fine on a
| number of Windows 7 systems, both 32-bit and 64-bit, but produces
| run-time error 430 (Class doesn't support Automation) on two different
| Windows XP based PCs.
|
| I've pinpointed the cause of the error message to the line:
|
| Set ShellClass = New Shell32.Shell
|
| in the following subprogram.
|
| Public Sub UnZip(sFileSource As String, sFileDest As String, ErrorFlag
| As Boolean)
| ' Unzips a zip file and puts its contents into a specified folder
|
| Dim ShellClass As Shell32.Shell
| Dim Filesource As Shell32.Folder
| Dim Filedest As Shell32.Folder
| Dim Folderitems As Shell32.Folderitems
|
| On Error GoTo UZ_1
| ErrorFlag = False
| Set ShellClass = New Shell32.Shell
| Set Filesource = ShellClass.NameSpace(sFileSource) ' should be zip
file
| Set Filedest = ShellClass.NameSpace(sFileDest) ' should be folder
| Set Folderitems = Filesource.Items
| Filedest.CopyHere Folderitems, 20
|
| ' Wait 1 second for separate thread
|
| Sleep 1000
|
| UZ_2:
| Set ShellClass = Nothing
| Set Filesource = Nothing
| Set Filedest = Nothing
| Set Folderitems = Nothing
|
| Exit Sub
| UZ_1: ErrCode = Err
| ErrorFlag = True
| ProcNum = 569
| ErrorHandler ErrCode
| Resume UZ_2
| End Sub
|
| Has anyone any thoughts or suggestions? The above code is based on that
| given at:
|
| http://www.vbforums.com/archive/index.php/t-534899.html
|
| AlexB


From: Dee Earley on
On 02/07/2010 15:12, Mayayana wrote:
> Why would you use a variable name FolderItems for
> a FolderItems object?! That's asking for trouble.

Why not?
They are different name spaces... :)

--
Dee Earley (dee.earley(a)icode.co.uk)
i-Catcher Development Team

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)
From: Mayayana on
| > Why would you use a variable name FolderItems for
| > a FolderItems object?! That's asking for trouble.
|
| Why not?
| They are different name spaces... :)
|

You sure do like to argue. Yes, they're different
namespaces. And the code also actually works
if one doesn't define the Shell32 namespace
explicitly. Then "Folderitems" becomes an ambiguous
name that can refer to a Folder object property or to
an object variable. All I said is that it's asking for trouble.


From: Alex Balfour on
Many thanks for your response.

> (I doubt
> that the Shell object reference is the actual error.)

That's definitely the line triggering the error.

> Nevertheless, your code works fine for me on XP.
> (Except that it shows a file-copy dialogue and seems
> to extract twice from the zip, because it asks for
> overwrite permission.

Interesting. On Windows 7, the unzipping process is invisible.

> You might be better off looking
> for a different way to extract the ZIP file.)

Any suggestions anyone? All I need is a simple unzip capability.

AlexB

On 02/07/2010 15:12, Mayayana wrote:
> A couple of things:
>
> Shell data types are funky. In some cases you'll
> get unexpected errors if you use those types because
> they're variant types that don't translate directly in
> VB. I think FolderItems is one of those types. (You
> can check it in the object browser.) Fortunately, you
> can still use variants. Anyplace where it acts up, try
> switching that data type to Object or reference it
> directly rather than assigning it to an object. (I doubt
> that the Shell object reference is the actual error.)
>
> Why would you use a variable name FolderItems for
> a FolderItems object?! That's asking for trouble.
>
> Nevertheless, your code works fine for me on XP.
> (Except that it shows a file-copy dialogue and seems
> to extract twice from the zip, because it asks for
> overwrite permission. You might be better off looking
> for a different way to extract the ZIP file.)
>
> Whatever the problem is I doubt very much that it's
> coming from the Shell object initialization.
>
> | In a freeware offering to which I'm adding a Currency Converter, I'm
> | downloading and unzipping a file of currency exchange rates from the
> | European Central Bank website each day. Everything is working fine on a
> | number of Windows 7 systems, both 32-bit and 64-bit, but produces
> | run-time error 430 (Class doesn't support Automation) on two different
> | Windows XP based PCs.
> |
> | I've pinpointed the cause of the error message to the line:
> |
> | Set ShellClass = New Shell32.Shell
> |
> | in the following subprogram.
> |
> | Public Sub UnZip(sFileSource As String, sFileDest As String, ErrorFlag
> | As Boolean)
> | ' Unzips a zip file and puts its contents into a specified folder
> |
> | Dim ShellClass As Shell32.Shell
> | Dim Filesource As Shell32.Folder
> | Dim Filedest As Shell32.Folder
> | Dim Folderitems As Shell32.Folderitems
> |
> | On Error GoTo UZ_1
> | ErrorFlag = False
> | Set ShellClass = New Shell32.Shell
> | Set Filesource = ShellClass.NameSpace(sFileSource) ' should be zip
> file
> | Set Filedest = ShellClass.NameSpace(sFileDest) ' should be folder
> | Set Folderitems = Filesource.Items
> | Filedest.CopyHere Folderitems, 20
> |
> | ' Wait 1 second for separate thread
> |
> | Sleep 1000
> |
> | UZ_2:
> | Set ShellClass = Nothing
> | Set Filesource = Nothing
> | Set Filedest = Nothing
> | Set Folderitems = Nothing
> |
> | Exit Sub
> | UZ_1: ErrCode = Err
> | ErrorFlag = True
> | ProcNum = 569
> | ErrorHandler ErrCode
> | Resume UZ_2
> | End Sub
> |
> | Has anyone any thoughts or suggestions? The above code is based on that
> | given at:
> |
> | http://www.vbforums.com/archive/index.php/t-534899.html
> |
> | AlexB
>
>