progressbar in a project

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lee123
    Contributor
    • Feb 2007
    • 556

    progressbar in a project

    i have been trying to add a progressbar to my project but don't know how and the last post i have posted one person answered it but never came back to help me with how?

    so i am asking again because this is something alot of people probably would want to know how to do it
    so i am placing a code down and hopefullly some one could post the steps on how this could and can be done. not just with my project but others too. so please have a heart and show us who don't know how, but want to learn to do it

    here is the code i am wanting to have a progressbar in it to show things happening

    Code:
    Private Sub cmdCopy_Click()
        Dim fso As New Scripting.FileSystemObject
        Dim fld As Folder
        cmdCopy.Caption = "Copying Folder!"
        Set fld = fso.GetFolder(txtSourceOfFolder)
        fld.Copy (txtDestinationOfFile)
        Label1.Caption = "Copying Folder Is Completed!"
        Beep
        txtSourceOfFolder.Text = ""
        txtDestinationOfFile.Text = ""
        cmdExit.Enabled = True
    End Sub
    as you can see from this code i have the button caption change when i click on it to say "Copying Folder!" and a label to say when it's done. this is great and all but a progressbar would look so much nicer and professional.


    lee123
  • tristanlbailey
    New Member
    • Apr 2007
    • 30

    #2
    The Visual Basic developer environment should offer a progress bar control for you to use. You can get it from the toolbox panel; the same place you got the command button from.

    Comment

    • lee123
      Contributor
      • Feb 2007
      • 556

      #3
      what? that's not what I'm Talking about. i know where the progressbar is located read the question again...

      Comment

      • lee123
        Contributor
        • Feb 2007
        • 556

        #4
        i want to know how to put it in my code to show something is going on, not that i don't know where it is.

        lee123

        Comment

        • tristanlbailey
          New Member
          • Apr 2007
          • 30

          #5
          Since your first post wasn't properly typed, I misunderstood.
          It may not have been what you meant, but it's pretty much what you typed.

          I haven't attempted this before, so I don't know if it will work. If it doesn't, you can use the overall structure to work out your own method.

          Create the folder first, so that you have an FSO for it. Enumerate the initial folder's file collection for the total number of files, using the Files property of the FSO. Apply that value to the progress bar's Maximum property. Then, do the copy operation. In a loop, enumerate the files in the same way with the new folder, to work out the current number of files that exist within the new folder, and increment the progress bar's Value property until the maximum value has been reached. Finally, display the "completed" message.

          Comment

          • lee123
            Contributor
            • Feb 2007
            • 556

            #6
            yea i guess your right after reading it again it kinda says that, well i guess I'm Sorry About that.tristanlbaily well i have a question lets say someone bring over some music you want to copy from a external hard drive the files may vary and then i wouldn't know what to set the max value to. thats why i made this program to copy my friends folder of music or songs

            lee123

            Comment

            • lee123
              Contributor
              • Feb 2007
              • 556

              #7
              o yea i forgot to tell you i don't know ho to do loops, well it's not that i haven't seen one i just never used them before. when i look at one i get confused on how to express it. sounds good when you say it in your head but when you typ it out it never works. that's why i placed the code in the first post so someone could help me place it in the code to understand how it's done. and i just noticed i misspelled your name sorry about that too.

              lee123

              Comment

              • lee123
                Contributor
                • Feb 2007
                • 556

                #8
                ok i have this, but this isn't working right some of the file are small but this is taking too long to finish.


                Code:
                Private Sub cmdCopy_Click()
                PBTask.Max = 100
                PBTask.Min = 0
                Dim i
                Dim fso As New Scripting.FileSystemObject
                Dim fld As Folder
                For i = 1 To 100
                        cmdCopy.Caption = "Copying Files!"
                        Set fld = fso.GetFolder(txtSourceOfFolder)
                        fld.Copy (txtDestinationOfFile)
                        PBTask.Value = (100 * (i / 100))
                      Next i
                        cmdExit.Enabled = True
                        txtSourceOfFolder.Text = ""
                        txtDestinationOfFile.Text = ""
                End Sub
                I did a search on progressbar and i found this code. added my stuff in it and this is what i have so why is it taking too long? I don't Understand how this is done.....I need help!!!!!!!

                lee123

                Comment

                • tristanlbailey
                  New Member
                  • Apr 2007
                  • 30

                  #9
                  Dont' use the code you've found; it's BAD.
                  The copy method is repeated 99 times, so it will of course be slow.

                  I presume you are using Visual Basic .NET, 2005, or 2008?

                  I am currently constructing code for the aforementioned; if you are using something older (i.e. Visual Basic 6 or VBA), please reply promptly.

                  Comment

                  • tristanlbailey
                    New Member
                    • Apr 2007
                    • 30

                    #10
                    I've just found something that you may be interested in:

                    http://vbnet.mvps.org/index.html?code/callback/filebackupcallb ack.htm

                    I tried making a simpler version, but it was taking too long. The sample above should be your "cup of tea".

                    Comment

                    • lee123
                      Contributor
                      • Feb 2007
                      • 556

                      #11
                      actually I'm using visual basic 6.0 enterprise edition.

                      lee123

                      Comment

                      • rpicilli
                        New Member
                        • Aug 2008
                        • 77

                        #12
                        Tell me one thing. What you realy want is:

                        1 - Show to the user of your app exactly how much was done, or

                        2 - Show to the user of your app that your program is doing something?

                        In the first case you will need to find the file size and use this value as the input for the value of progress bar. In my option to much work for nothing.

                        In the second case, you can change the Style property of the status bar from Blocks (default value) to Marquee. Doing this the status bar will keep moving always. You can use the property Visible = true to show the status bar just before the file.copy instruction and Visible = False just after the copy is finished.

                        I hope this help.

                        Rogerio

                        Comment

                        • lee123
                          Contributor
                          • Feb 2007
                          • 556

                          #13
                          Rpicilli, does both of these use the timer control because when i did it without the timer it takes too long, and actually i want to see what is going on so the second one

                          lee123

                          Comment

                          • tristanlbailey
                            New Member
                            • Apr 2007
                            • 30

                            #14
                            Did you look at the link I provided?

                            The code in the article should work in VB6.

                            Comment

                            • lee123
                              Contributor
                              • Feb 2007
                              • 556

                              #15
                              yes i did and i actually made the program to see it worked and it worked but alot of coding.

                              lee123

                              Comment

                              Working...