Solved

Put file in the trassh can.

Posted on 1999-01-29
10
203 Views
Last Modified: 2010-05-03
I took an example in a book, and try to work it but i have always the error SUB OR FUNCTION NOT DEFINED for w95Recycle. If i put the commondialog vb doesn't reconize FileOpen.

 Here is my code:

This Project call the modules.
Project Corbeil :

Private Sub Command1_Click()
      'utilise la corbeille de Windows et remplace
      'la commande Kill de VB
      ReDim Fichiers(1 To 1) As Variant
      'DlgTitle$ = "Sélection (multiple) de fichiers à supprimer"
      'Filter$ = "Tous Fichiers (*.*)|*.*"
      'SelectFich$ = FileOpen(DlgTitle$, Filter$, True)
      SelectFich$ = "C:\api\allo.csa"
      PathExtract = False
      Do While Len(SelectFich$) > 0
        'fichiers séparés par des caractères vides
        SepPos% = InStr(SelectFich$, " ")
        If SepPos% = 0 Then
            Counter% = Counter% + 1
            ReDim Preserve Fichiers(1 To Counter%)
            FichierSuivant$ = SelectFich$
            SelectFich$ = ""
            Fichiers(Counter%) = FichierSuivant$
          Else
            If PathExtract = False Then
                 Chemin$ = Mid$(SelectFich$, 1, SepPos% - 1)
                 SelectFich$ = Mid$(SelectFich$, SepPos% + 1)
                 'chemin au début de la chaîne
                 If Right$(Chemin$, 1) <> "\" Then Chemin$ = Chemin$ + "\"
                 PathExtract = True
               Else
                 'tous les autres morceaux sont des noms de fichier
                 FichierSuivant$ = Mid$(SelectFich$, 1, SepPos% - 1)
                 SelectFich$ = Mid$(SelectFich$, SepPos% + 1)
                 'redimensionnement du tableau, sans perte des données
                 Counter% = Counter% + 1
                 ReDim Preserve Fichiers(1 To Counter%)
                 Fichiers(Counter%) = FichierSuivant$
            End If
        End If
      Loop
      'à la Corbeille, on l'aime bien
      w95Recycle Me.hwnd, Fichiers()

End Sub

Project with modules :
Corbeil.bas :

Option Explicit

'fichiers à la corbeille
Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long

Type SHFILEOPSTRUCT
  hwnd As Long
  wFunc As Long
  pFrom As String
  pTo As String
  fFlags As Integer
  fAnyOperationsAborted As Long
  hNameMappings As Long
  lpszProgressTitle As String
End Type

Corbeil.cls :

Public Sub w95Recycle(hwnd As Long, Fichiers() As Variant)
  'envoi de fichiers à la corbeille
  Dim SHFileOp As SHFILEOPSTRUCT
  Dim fList As String
  'tableau présent ?
  If LBound(Fichiers) <> 1 Then Exit Sub
  If UBound(Fichiers) = 0 Then Exit Sub
  For X% = LBound(Fichiers) To UBound(Fichiers)
    fList = fList & Fichiers(X%) & vbNullChar
  Next X%
  fList = fList & vbNullChar
  'remplissage de la structure
  With SHFileOp
    .hwnd = hwnd&
    .wFunc = &H3   'suppression
    .pFrom = fList 'liste des fichiers
    .fFlags = &H40 'annulation possible
    .lpszProgressTitle = "Supprimer..."
  End With
  R& = SHFileOperation(SHFileOp)
End Sub

If you have a better way to do this i can accept it.
Thank's a lot.
0
Comment
Question by:dosyl
  • 5
  • 4
10 Comments
 
LVL 8

Accepted Solution

by:
MikeP090797 earned 100 total points
ID: 1471222

You can use this one:


Type SHFILEOPSTRUCT     'Send files to recycled bin
        hwnd As Long
        wFunc As Long
        pFrom As String
        pTo As String
        fFlags As Integer
        fAnyOperationsAborted As Long
        hNameMappings As Long
        lpszProgressTitle As String
End Type
Public Const FO_DELETE = &H3      'Send files to recycled bin
Public Const FOF_ALLOWUNDO = &H40
Public Const FOF_SILENT = &H4
Public Const FOF_NOCONFIRMATION = &H10

Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long

'PURPOSE:   Deletes files by sending them to recycled bin
'ARGUMENTS:
'   IN szFiles:         files to delete
'   IN bShowPrompt:     Specifies whether to ask the user to confirm the deletition
'   IN bShowProgress:   Specifies whether to display a progress information
Public Sub SendToRecycledBin(szFiles As String, Optional bShowPrompt As Boolean = True, Optional bShowProgress As Boolean = True)
       Dim fo As SHFILEOPSTRUCT
       fo.hwnd = 0&
       fo.wFunc = FO_DELETE
       fo.pFrom = szFiles
       fo.pTo = ""
       fo.fFlags = FOF_ALLOWUNDO Or IIf(bShowPrompt, 0, FOF_NOCONFIRMATION) Or IIf(bShowProgress, 0, FOF_SILENT)
       SHFileOperation fo
End Sub

0
 
LVL 2

Expert Comment

by:spenner
ID: 1471223
If you want to send a file to the recycle bin, you can just move it to c:\recycled
0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1471224
He can't because the place of the recycled bin is different from computer to computer
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 1

Author Comment

by:dosyl
ID: 1471225
Dim fo As SHFILEOPSTRUCT

I have an error with this : Expected : End with statement.
Why?
0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1471226
Did you put the declarations at the top as well?
0
 
LVL 1

Author Comment

by:dosyl
ID: 1471227
'I wrted this in the class module:
Public Sub w95Recycle(hwnd As Long, Fichiers() As Variant)
  'envoi de fichiers à la corbeille
  Dim SHFileOp As SHFILEOPSTRUCT
  Dim fList As String
  'tableau présent ?
  If LBound(Fichiers) <> 1 Then Exit Sub
  If UBound(Fichiers) = 0 Then Exit Sub
  For X% = LBound(Fichiers) To UBound(Fichiers)
    fList = fList & Fichiers(X%) & vbNullChar
  Next X%
  fList = fList & vbNullChar
  'remplissage de la structure
  With SHFileOp
    .hwnd = hwnd&
    .wFunc = &H3   'suppression
    .pFrom = fList 'liste des fichiers
    .fFlags = &H40 'annulation possible
    .lpszProgressTitle = "Supprimer..."
  End With
  R& = SHFileOperation(SHFileOp)
End Sub


'PURPOSE:   Deletes files by sending them to recycled bin
'ARGUMENTS:
'   IN szFiles:         files to delete
'   IN bShowPrompt:     Specifies whether to ask the user to confirm the deletition
'   IN bShowProgress:   Specifies whether to display a progress information
Public Sub SendToRecycledBin(szFiles As String, Optional bShowPrompt As Boolean = True, Optional bShowProgress As Boolean = True)
       Dim fo as SHFILEOPSTRUCT      'it's write inred here
       fo.hwnd = 0&
       fo.wFunc = FO_DELETE
       fo.pFrom = szFiles
       fo.pTo = ""
       fo.fFlags = FOF_ALLOWUNDO Or IIf(bShowPrompt, 0, FOF_NOCONFIRMATION) Or IIf(bShowProgress, 0, FOF_SILENT)
       SHFileOperation fo
End Sub


0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1471228
Put the whole I gave you in a regular module (.bas)
0
 
LVL 1

Author Comment

by:dosyl
ID: 1471229
Ihave the same error : SendToRecycledBin not defined. Why? Why?
0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1471230
email me the project to michaelp@gezernet.co.il, i'll try to fix it
0
 
LVL 1

Author Comment

by:dosyl
ID: 1471231
Here is MikeP code  and it works :
*******************Corbeil.frm****************************

Private Sub Command1_Click()
      'utilise la corbeille de Windows et remplace
      'la commande Kill de VB
      ReDim Fichiers(1 To 1) As String
      DlgTitle$ = "Sélection (multiple) de fichiers à supprimer"
      Filter$ = "Tous Fichiers (*.*)|*.*"
      SelectFich$ = FileOpen(DlgTitle$, Filter$, True)
      PathExtract = False
      Do While Len(selectfich$) > 0
        'fichiers séparés par des caractères vides
        SepPos% = InStr(selectfich$, " ")
        If SepPos% = 0 Then
            Counter% = Counter% + 1
            ReDim Preserve Fichiers(1 To Counter%)
            FichierSuivant$ = selectfich$
            selectfich$ = ""
            Fichiers(Counter%) = FichierSuivant$
          Else
            If PathExtract = False Then
                 Chemin$ = Mid$(selectfich$, 1, SepPos% - 1)
                 selectfich$ = Mid$(selectfich$, SepPos% + 1)
                 'chemin au début de la chaîne
                 If Right$(Chemin$, 1) <> "\" Then Chemin$ = Chemin$ + "\"
                 PathExtract = True
               Else
                 'tous les autres morceaux sont des noms de fichier
                 FichierSuivant$ = Mid$(selectfich$, 1, SepPos% - 1)
                 selectfich$ = Mid$(selectfich$, SepPos% + 1)
                 'redimensionnement du tableau, sans perte des données
                 Counter% = Counter% + 1
                 ReDim Preserve Fichiers(1 To Counter%)
                 Fichiers(Counter%) = FichierSuivant$
            End If
        End If
      Loop
      'à la Corbeille, on l'aime bien
 
SendToRecycledBin Fichiers(Counter%)
End Sub

*****************Corbeil.bas*************************
Option Explicit

'fichiers à la corbeille
Public Type SHFILEOPSTRUCT
  hwnd As Long
  wFunc As Long
  pFrom As String
  pTo As String
  fFlags As Integer
  fAnyOperationsAborted As Long
  hNameMappings As Long
  lpszProgressTitle As String
End Type

Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As Any) As Long

Private Const FO_DELETE = &H3 'Send files to recycled bin
Private Const FOF_ALLOWUNDO = &H40
Private Const FOF_SILENT = &H4
Private Const FOF_NOCONFIRMATION = &H10

'PURPOSE:   Deletes files by sending them to recycled bin
'ARGUMENTS:
'   IN szFiles:         files to delete
'   IN bShowPrompt:     Specifies whether to ask the user to confirm the deletition
'   IN bShowProgress:   Specifies whether to display a progress information
Public Sub SendToRecycledBin(szFiles As String, Optional bShowPrompt As Boolean = True, Optional bShowProgress As Boolean = True)
Dim fo As SHFILEOPSTRUCT
fo.hwnd = 0&
fo.wFunc = FO_DELETE
fo.pFrom = szFiles
fo.pTo = ""
fo.fFlags = FOF_ALLOWUNDO Or IIf(bShowPrompt, 0, FOF_NOCONFIRMATION) Or IIf(bShowProgress, 0, FOF_SILENT)
Dim x As Long
x = SHFileOperation(fo)
End Sub

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question