Results 1 to 16 of 16

Thread: [RESOLVED] Progress bar question

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2007
    Posts
    520

    Resolved [RESOLVED] Progress bar question

    Heya guys

    I have got a progress bar that i want to move in accordance with the process of copying files. Basically i am creating an update program that checkes to see if the version on the server is more up-to-date than the one on the local machine, then if it its up-to-date and open the file if its not up-to-date it deletes a set of files and then copies the files from the server to the local machine.

    How can i get a progress bar to move in relation to how much of the progress is completed?

    thank you in advance

    Frosty

  2. #2
    New Member
    Join Date
    Jul 2008
    Location
    Australia
    Posts
    1

    Re: Progress bar question

    I'm quite new to VB myself, but what I would do personally is change the bar state every so often within the code.
    vb Code:
    1. 'check a couple of files
    2. Me.ProgressBar1.Value = 40
    3. 'check some more..
    4. Me.ProgressBar1.Value = 80
    5. 'etc etc
    6. 'if they need updating, probably cycle the bar backwards
    7. Me.ProgressBar1.Value = 50
    8. 'etc etc again
    But like I said, I'm new so excuse me if I'm.. way off.

  3. #3
    Member Daarklord's Avatar
    Join Date
    Jul 2008
    Posts
    54

    Re: Progress bar question

    You'd want to set the ProgressBars's Step and Maximum values. Then call the PerformStep at appropriate times. If you had 50 files to download then Maximum would be 50 and Step would be 1 and each time a file downloads, call PerformStep. If you're working with one large file you'll have to check its size vs its maximum size. My.Computer.FileSystem.GetFileInfo will get you the file size.
    0xABADA55D00D

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Progress bar question

    is this all local as in your copies are being made via normal file copy, or is the server being accessed via HTTP/FTP?

  5. #5
    Member Daarklord's Avatar
    Join Date
    Jul 2008
    Posts
    54

    Re: Progress bar question

    I was assuming wherever the source is, you'd be able to request the file size before the download, then check it against the size of the file you have locally.
    0xABADA55D00D

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2007
    Posts
    520

    Re: Progress bar question

    it is all done locally over a network there is no HTTp/FTP involved.
    I have got the idea of copying all teh files etc working its just the progress bar that i am struggling with

  7. #7
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Progress bar question

    well as was mentioned earlier in this thread, if you know the number of files you are going to copy ahead of time, you can just set the progressbars max to that value, and increment it by 1 each time a file is copied. While size will matter and fluctuate the actual copy times of each file, the progessbar itself is not a measure of time, its a measure of progress, so I wouldn't even bother calculating file sizes to work into the progressbar's updating. Especially if its over a local network, since file copies should be relatively quick.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2007
    Posts
    520

    Re: Progress bar question

    how can i copy all the files in and individual folder seperatly adn increment the progress bar with each one. What if i dont know how many files there are in thr first place? Is there anyway you can search a folder to get how many files are in there?

  9. #9
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Progress bar question

    You mentioned

    "I have got the idea of copying all teh files etc working its just the progress bar that i am struggling with"
    so what does that code look like now?

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2007
    Posts
    520

    Re: Progress bar question

    it looks like this at the moment:

    Code:
    My.Computer.FileSystem.DeleteDirectory(My.Computer.FileSystem.SpecialDirectories.ProgramFiles & "\PHC Admin System\System", FileIO.DeleteDirectoryOption.DeleteAllContents)
    My.Computer.FileSystem.CreateDirectory(My.Computer.FileSystem.SpecialDirectories.ProgramFiles & "\PHC Admin System\System")
    My.Computer.FileSystem.CopyDirectory("\\sqlserver\SQLServerHDD\PHC Admin System", My.Computer.FileSystem.SpecialDirectories.ProgramFiles & "\PHC Admin System\System\")

  11. #11
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Progress bar question

    the CopyDirectory method is just going to copy the entire directory and block your app until it is done. It doesn't report any progress, so you can't use it to know how far along it is.

    You want to grab all the files in the directory, and copy them 1 by 1.

    Try something like this:

    Code:
            Dim localDirectory As String = My.Computer.FileSystem.SpecialDirectories.ProgramFiles & "\PHC Admin System\System"
            Dim remoteDirectory As String = "\\sqlserver\SQLServerHDD\PHC Admin System"
    
            My.Computer.FileSystem.DeleteDirectory(localDirectory, FileIO.DeleteDirectoryOption.DeleteAllContents)
            My.Computer.FileSystem.CreateDirectory(localDirectory)
    
            Dim filesToCopy As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = _
                My.Computer.FileSystem.GetFiles(remoteDirectory)
    
            ProgressBar1.Maximum = filesToCopy.Count
            ProgressBar1.Value = 0
            ProgressBar1.Minimum = 0
    
            For Each fileName As String In filesToCopy
                My.Computer.FileSystem.CopyFile(fileName, localDirectory & "\" & IO.Path.GetFileName(fileName), True)
                ProgressBar1.Value += 1
            Next

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2007
    Posts
    520

    Re: Progress bar question

    will that also work if there are folders in there will it copy all the folders in there as well as the files

  13. #13
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Progress bar question

    no, but it could be extended to do so.

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2007
    Posts
    520

    Re: Progress bar question

    how could it be extended to include folders aswell?

  15. #15
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Progress bar question

    by changing the line of code that grabs the files to this:

    Code:
            Dim filesToCopy As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = _
                My.Computer.FileSystem.GetFiles(remoteDirectory, FileIO.SearchOption.SearchAllSubDirectories)

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2007
    Posts
    520

    Re: Progress bar question

    Brilliant thank you very much kleinma

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