Results 1 to 8 of 8

Thread: progress bar

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    43

    progress bar

    i'm running a program that i made that finds and copies to a new directory close to 5k files. i'm wondering if i can incorporate a message box or a progress bar that shows the progress of the files copied to the user.

    the program is pretty straight forward. i've never done anything using a progress bar before though. any help would be fantastic.

    thank you!

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: progress bar

    If you use this copy method ...

    My.Computer.FileSystem.CopyFile("source.file", "targetfile", Microsoft.VisualBasic.FileIO.UIOption.AllDialogs)

    ... you get all the same progress dialogs you would get copying/moving in Explorer.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    43

    Re: progress bar

    that's awesome! the only thing is that this moving is taking place over a network. right now i'm using something like this

    MessageBox.Show(filecount & "files were copied", "Copied Files", MessageBoxButtons.OK)

    i just think it would be cool to have something a little more visual.

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: progress bar

    Quote Originally Posted by bsanders View Post
    that's awesome! the only thing is that this moving is taking place over a network. right now i'm using something like this

    MessageBox.Show(filecount & "files were copied", "Copied Files", MessageBoxButtons.OK)

    i just think it would be cool to have something a little more visual.
    That doesn't move or copy anything, it just shows a message and does nothing until the user close it. It doesn't matter if it's done over the network or not, try the code provided before you toss it away.

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    43

    Re: progress bar

    i applied to my code in place of my original File.Copy(file, file) it copied well but didn't give any visual feed back. my message box is after the move takes place as the program is counting the files then gives the pop up as a confirmation if you will of the move.

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: progress bar

    You haven't posted any code but your MessageBox call. Did you try using the method dunfiddlin showed you? If you do you will get a progress dialog auto-magically.

  7. #7

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    43

    Re: progress bar

    for example here is a part of code

    Code:
     For Each f As String In Directory.EnumerateFiles(G.StagingDirectory, pattern, SearchOption.AllDirectories)
    
                Dim fileName As String = Path.GetFileName(f)
                Dim Qname As String
                If (quarter.Substring(4, 2)) = "03" Then
                    Qname = "Q1"
                End If
                If (quarter.Substring(4, 2)) = "06" Then
                    Qname = "Q2"
                End If
                If (quarter.Substring(0, 6)) = "09" Then
                    Qname = "Q3"
                End If
                If (quarter.Substring(0, 6)) = "12" Then
                    Qname = "Q4"
                End If
                newName = fileName.Replace(quarter, Qname & quarter.Substring(0, 4))
                    File.Copy(f, G.StagingDirectory & newName)
                    filecount = filecount + 1
                File.Delete(f)
    
            Next
    
                MessageBox.Show(filecount & " files were renamed", "Renamed Files", MessageBoxButtons.OK)
    when i comment out the File.Copy(f, G.StagingDirectory & newName) line and replace it with the one that was given above the file copy still takes place but there is no visual aspect to it at all. the message box is really just for reassurance to the user that the files were in fact moved.

    the progress bar isn't anything that is required per se but i think it would be really cool to add it and as i'm still getting my wings as they say it would be cool to tinker with and learn.

    thank you!

  8. #8
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: progress bar

    there is no visual aspect to it at all
    How big are the individual files? If they're small(ish) then there won't be time for the dialog to show before they are completed (compare it to what happens if you use Explorer). If you want to use a progress bar for the whole loop then you're going to need some way to get a count of the files so you wouldn't be able to use the current For Each loop in the same way. After that it's just simple counting ...

    ProgressBar1.Maximum = files.Count - 1

    ... then every time a file is copied ..

    ProgressBar.Value += 1
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

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