?
Solved

Put file in the trassh can.

Posted on 1999-01-29
10
Medium Priority
?
209 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 8

Accepted Solution

by:
MikeP090797 earned 400 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Suggested Courses
Course of the Month14 days, 16 hours left to enroll

770 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