Results 1 to 3 of 3

Thread: [RESOLVED] dim "blah" as Shell32 problem?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Resolved [RESOLVED] dim "blah" as Shell32 problem?

    got this code from codebank i got the create_empty_zip working excellent but when i get to zip a folder or file i get error on

    vb Code:
    1. Private Sub Zip_Activity(Action As String, sFileSource As String, sFileDest As String)
    2.  
    3.     '//copies contents of folder to zip file
    4.     Dim ShellClass  As Shell32.Shell    'I GET ERROR HERE it doesnt exist in my list
    5.     Dim Filesource  As Shell32.Folder 'error
    6.     Dim Filedest    As Shell32.Folder  'error
    7.     Dim Folderitems As Shell32.Folderitems 'errors
    8.    
    9.     If sFileSource = "" Or sFileDest = "" Then GoTo EH
    10.                
    11.     Select Case UCase$(Action)
    12.        
    13.         Case "ZIPFILE"
    14.            
    15.             If Right$(UCase$(sFileDest), 4) <> ".ZIP" Then
    16.                 sFileDest = sFileDest & ".ZIP"
    17.             End If
    18.            
    19.             If Not Create_Empty_Zip(sFileDest) Then
    20.                 GoTo EH
    21.             End If
    22.        
    23.             Set ShellClass = New Shell32.Shell
    24.             Set Filedest = ShellClass.NameSpace(sFileDest)
    25.            
    26.             Call Filedest.CopyHere(sFileSource, 20)
    27.                
    28.         Case "ZIPFOLDER"
    29.            
    30.             If Right$(UCase$(sFileDest), 4) <> ".ZIP" Then
    31.                 sFileDest = sFileDest & ".ZIP"
    32.             End If
    33.            
    34.             If Not Create_Empty_Zip(sFileDest) Then
    35.                 GoTo EH
    36.             End If
    37.        
    38.             '//Copy a folder and its contents into the newly created zip file
    39.             Set ShellClass = New Shell32.Shell
    40.             Set Filesource = ShellClass.NameSpace(sFileSource)
    41.             Set Filedest = ShellClass.NameSpace(sFileDest)
    42.             Set Folderitems = Filesource.Items
    43.            
    44.             Call Filedest.CopyHere(Folderitems, 20)
    45.        
    46.         Case "UNZIP"
    47.            
    48.             If Right$(UCase$(sFileSource), 4) <> ".ZIP" Then
    49.                 sFileSource = sFileSource & ".ZIP"
    50.             End If
    51.            
    52.             Set ShellClass = New Shell32.Shell
    53.             Set Filesource = ShellClass.NameSpace(sFileSource)      '//should be zip file
    54.             Set Filedest = ShellClass.NameSpace(sFileDest)          '//should be directory
    55.             Set Folderitems = Filesource.Items                      '//copy zipped items to directory
    56.            
    57.             Call Filedest.CopyHere(Folderitems, 20)
    58.        
    59.         Case Else
    60.        
    61.     End Select
    62.            
    63.     '//Ziping a file using the Windows Shell API creates another thread where the zipping is executed.
    64.     '//This means that it is possible that this console app would end before the zipping thread
    65.     '//starts to execute which would cause the zip to never occur and you will end up with just
    66.     '//an empty zip file. So wait a second and give the zipping thread time to get started.
    67.  
    68.     Call Sleep(1000)
    69.    
    70. EH:
    71.  
    72.     If Err.Number <> 0 Then
    73.         MsgBox Err.Description, vbExclamation, "error"
    74.     End If
    75.  
    76.     Set ShellClass = Nothing
    77.     Set Filesource = Nothing
    78.     Set Filedest = Nothing
    79.     Set Folderitems = Nothing
    80.  
    81. End Sub

    how come i do not have the Shell32 option to dim as?

    is it normal that i do not have it or do i have to install something or i can dim it a different way? i need some advice/help

    thanks in advance

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: dim "blah" as Shell32 problem?

    add a reference to shell automation?
    or i can dim it a different way?
    you can use latebinding and declare all as objects
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: dim "blah" as Shell32 problem?

    thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width