troubleshooting Question

Program Bar dosen't function and Program freezes

Avatar of NUPE2006
NUPE2006 asked on
Visual Basic Classic
5 Comments1 Solution236 ViewsLast Modified:
When I run the code below it freezes up and the progress bar dosen't function. Can someone let me know where I went wrong, what I did wrong, and methods to fix the problems? Thanks and I appreciate it.
Private Sub cmdYesD_Click()
    Dim File1 As File
    Dim Folder1 As Folder
    Dim FileCollection As Folder
    Dim fso As New FileSystemObject
    Dim strRegion2 As String
    Dim intDays2 As Integer
    Dim intDelete As Integer
    Dim intDeleteFolder As Integer
    Dim TotalFiles As Integer
    Dim ProcessedFiles As Integer
    strRegion2 = Me.txtRegionConf.Text
    intDays2 = Me.txtInputDays.Text
    ProcessedFiles = 0
    'intDelete = 0
    'intDeleteFolder = 0
    
'Deletes Files
    If fso.FolderExists("Z:\" & strRegion2 & "\Customer\Output") Then
        Set FileCollection = fso.GetFolder("Z:\" & strRegion2 & "\Customer\Output")
'Set progress bar maximum to files + folders
        TotalFiles = FileCollection.Files.Count + FileCollection.SubFolders.Count
        Me.ProgressBar1.Max = TotalFiles
'search for and delete files
        'Call Cleanfiles
        For Each File1 In FileCollection.Files
'Move Progressbar
            ProcessedFiles = ProcessedFiles + 1
            Me.ProgressBar1.Value = ProcessedFiles
        Do
                If DateDiff("d", FileDateTime(File1), Now) >= intDays2 Then
                    fso.DeleteFile (File1)
                    intDelete = intDelete + 1
                End If
        Loop
    Next
    'Next
        'Call Cleanfolders
        For Each Folder1 In FileCollection.SubFolders
'Move Progressbar
            ProcessedFiles = ProcessedFiles + 1
            Me.ProgressBar1.Value = ProcessedFiles
        Do Until TotalFiles
                If DateDiff("d", Folder1.DateCreated, Now) >= intDays2 Then
                    fso.DeleteFolder (Folder1)
                    intDeleteFolder = intDeleteFolder + 1
                End If
        Loop
    Next
  MsgBox "Complete.  Deleted: " & vbCrLf & intDelete & " files and " & vbCrLf & intDeleteFolders & " Folders"
        Else
        Call RegionError
    End If
            Me.Hide
            frmFFMMain.Show
End Sub
________________________________________________________________________
Public Function RegionError()
    'If fso.FolderExists("Z:\" & strRegion2 & "\Customer\Output") = False Then
                    MsgBox "Error: Region not Found"
                        Me.Hide
                        frmFFMMain.Show
                'End If
End Function
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros