Progress Bar Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Atrox
    New Member
    • Nov 2007
    • 3

    Progress Bar Help

    Hi, I'm fairly new to Visual Basic and am having problems getting the progress bar to work. I swap about 12 5-15MB files regularly to suit my needs and want to do this automatically. Ive only been working with VBScript for about 48hrs, so my knowledge base isn't that great. I've done most of the scripting so far though trial and error.
    So if anyone can direct me to a simple tutorial or write a code that i can easily modify would be great.

    Thanks,
    Atrox
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Have you made an attempt at it yourself? What's the main problem - determining where you are in the process, or getting the ProgressBar to display it? They are really two separate things, both fairly simple once you play around a bit.

    Also, you didn't say what version of VB you're using.

    Comment

    • Atrox
      New Member
      • Nov 2007
      • 3

      #3
      Im using VB 2005. Ive spent a day or two looking for a way progress bar to show how far through the process is, and there is 6 different file processes, each copying around 12 large files, that id like linked to the progress bar. Ive also tried writing it myself, but I have no idea what commands to use yet.

      I know the code below has something to do with it, but I have no idea what to add or change, apart from the Minimum, Maximum values and the Value it self; nor where to put it.

      Code:
              With ProgressBar1
                  .Minimum = 1
                  .Maximum = 100000
                  .Value = 1
                  .Step = 1
      
                  For i As Integer = .Minimum To .Maximum
                      ' Perform one step of the action being tracked.
                      .PerformStep()
                  Next i
      
              End With
      Would My.Computer.Fil esSystem have to be added in there somewhere?

      I have some other issues that I have, but I'll ask them later as not to confuse myself.

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        In my experience, the general process would be...

        Set Min/Max of the progress bar to count from 0 or 1 to either 100 or 1000. Unless you have the world's highest screen resolution, there's probably not much point trying to display 100,000 steps on it. At any point, you can just set .Value to CurrentPosition / TotalToBeDone * 100 (or * 1000 of course).

        Don't loop through the progress bar. It's just a display device. As you go through your process, you periodically (based on time elapsed, bytes copied, number of files completed or whatever seems appropriate) you update the progress bar to reflect where you're up to.

        A lot will depend on the processed you're performing. For instance, if you do one command to copy a file, then you probably can't hope to show the progress of that copy since your code won't regain control until it's finished.

        As for the "My.Compute r" stuff, I have no idea. That's a foreign language to me, since I use VB6.
        Last edited by Killer42; Nov 12 '07, 02:31 AM.

        Comment

        • Atrox
          New Member
          • Nov 2007
          • 3

          #5
          Well I have the bar actually doing something now, but its not accurately showing the process. It starts "Jumping" backwards and forwards after the first few files have been copied. Here is an example of the code I'm using

          Code:
             
                  My.Computer.FileSystem.CopyFile( _
                  "C:\testfile.txt", _
                  "C:\Backup\textfile.txt")
          
                  With ProgressBar1
                      .Minimum = 0
                      .Maximum = 1000
                      .Value = 52.631
                      .Step = 1
          
                      For i As Integer = .Minimum To .Maximum
                          ' Perform one step of the action being tracked.
                          .PerformStep()
                      Next i
          
                  End With
          
                  My.Computer.FileSystem.CopyFile( _
                   "C:\testfile2.txt", _
                  "C:\Backup\testfile2.txt")
          
                  With ProgressBar1
                      .Minimum = 0
                      .Maximum = 1000
                      .Value = 52.631
                      .Step = 2
          
                      For i As Integer = .Minimum To .Maximum
                          ' Perform one step of the action being tracked.
                          .PerformStep()
                      Next i
          
                  End With
          
                  My.Computer.FileSystem.CopyFile( _
                   "C:\testfile3.txt", _
                  "C:\Backup\testfile3.txt")
          
                  With ProgressBar1
                      .Minimum = 0
                      .Maximum = 1000
                      .Value = 52.631
                      .Step = 3
          
                      For i As Integer = .Minimum To .Maximum
                          ' Perform one step of the action being tracked.
                          .PerformStep()
                      Next i
          
                  End With
          I have set the value to 52.631 because it divides evenly into 1000 by 19.

          The code above isn't actually what I'm using, apart from the values.

          What am I doing wrong?

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            It looks as thought the ProgressBar control works a bit differently in your version to what I'm used to in VB6. However, my guess is that .Step is not the appropriate property to be changing along the way. I think you'll find that what you want is to set .Value to multiples of your "52.xxx" after copying each file.

            In other words, after copying the first file set it to 52.whatever. After the second file, set it to twice as much. And so on.

            Comment

            • mshefeek
              New Member
              • Nov 2007
              • 2

              #7
              I worked In .Net2003. Instead of My.Computer.Fil eSystem.copyfil e
              we need to write FileSystem.File copy

              Comment

              • QVeen72
                Recognized Expert Top Contributor
                • Oct 2006
                • 1445

                #8
                Hi,

                You have written the code Sequentially, Your code will copy the File and after that, move the ProgressBar and so on..

                Place a Timer Control on the Form.
                Check approximate Time Required To Copy using FSO for approx 1 mb ..say 20 seconds...

                It should be in this Sequence:

                Place a Timer set the Timer's Interval to 20000 (20 X 1000 ms)
                Set the Values of Progressbar : Min = 0 and Max = Size of File in Mb
                Start the Timer
                Start Copying of File
                In Timer1_Timer Event Change the Value of Progress Bar.
                After Reaching Max Value, Disable the Timer..
                Or After Copy Completion of the File Disable the Timer

                Regards
                Veena

                Comment

                Working...