progressbar in a project

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • smartchap
    New Member
    • Dec 2007
    • 236

    #16
    Dear lee123
    I have already given clue to same problem in some forum (which I don't remember at present).
    First of all about your program taking too long to complete:
    You have unneccessarily used For..Next loop, in this loop u have used copying of folder which is being copied 100 times again & again and Progress bar is increasing 1 to 100 simply showing that how many times folders is copied.
    Now I just give u an idea (of course I will try a program and will post it here):
    First, u read the number of files in the folder to be copied (say it is SFolder) and create a Destination folder (may be DFolder). Set max value of PBar to number of files in SFolder. Now copy all the files (using a loop) one by one from SFolder to DFolder and increase the value of PBar to number of files copied.
    Second, read total number of bytes in SFolder, set max value of PBar to it. Copy files one by one and increase value of PBar as number of bytes copied increases.
    Hope it will give an idea and help u.

    Comment

    • lee123
      Contributor
      • Feb 2007
      • 556

      #17
      hello..smartcha p i have waited for you to answer some questions in our last post under "Progressba r" after waiting for a while i moved to this post to see if someone else could help. at the end of your post in the last posting you said:
      ("If you have any other query please post the code to understand the problem exactly and give solution.") well i waited and no one..anyway let me see if i understand what your saying: and try to figure it out..but the looping is what i don't understand yet becaue i haven't really used it in any of my projects i have made the looping you see is from someone elses code i tried..I'm afraid to say i don't understand how it works..i have to work on this looping until i understand it completely..tha nks for answering and coming back to my problem.

      lee123

      Comment

      • smartchap
        New Member
        • Dec 2007
        • 236

        #18
        Actually I was a little bit busy these days and couldn't open Internet so can't check the subscribed posts. Please try my suggestions and if need further help ask me. As I said I will try same and will post the code, but after some days as I am really busy these days.

        Comment

        • rpicilli
          New Member
          • Aug 2008
          • 77

          #19
          Hi

          This is a functional application that copy files and/or directory. Try to understant the CODE.

          There in no easy way to create programs. If you do not have time to read a lot, you'll not be a good programmer. Excuse me to tell you that but I'm a 52 years old programmer and I learn something new every day.

          Besides the code you can see the form image at www.maxidoc.com .br/help.png

          In this image you'll see all the names used in the components and the design of the screen.

          The components that has no name, let them as the default names.

          Create a new project. Open the code of the form1. Copy all the following code into the Form1 code pane. Put the components and rename following the image that you can see in the address above.

          I hope you can do it. May be you have problem but if you realy are a programmer, don't give up.



          [CODE]

          Imports System.IO

          Public Class Form1

          Private Sub butCopy_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles butCopy.Click
          'Show the progress bar
          Me.ProgressBar1 .Visible = True
          'Verify type of copy (Dir or File)
          If Me.butCopy.Text = "Copy Directory" Then
          'Copy Directory
          subCopyDir(Me.t xtFileSource.Te xt, Me.txtDirDestin ation.Text)
          Else
          'Copy file
          subCopyFil(Me.t xtFileSource.Te xt, Me.txtDirDestin ation.Text & "\" & Me.TextBox1.Tex t)
          End If
          'Hide the progressbar
          Me.ProgressBar1 .Visible = False
          MessageBox.Show ("Copy End")
          End Sub

          Private Sub butBrowseSource _Click(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles butBrowseSource .Click
          Dim bResult As DialogResult
          If Me.chkFileOrDir .Checked Then
          'Directory
          bResult = Me.FolderBrowse rDialog1.ShowDi alog
          Else
          'File
          bResult = Me.OpenFileDial og1.ShowDialog
          End If

          'If cancel button was cicked return to main form
          If bResult = Windows.Forms.D ialogResult.Can cel Then Exit Sub

          If Me.chkFileOrDir .Checked Then
          'Put the Directory name on the text box
          Me.txtFileSourc e.Text = Me.FolderBrowse rDialog1.Select edPath.ToString ()
          Else
          'Put the file name on the text box
          Me.txtFileSourc e.Text = Me.OpenFileDial og1.FileName.To String()
          'Put the same file name that could be change if necessary
          Me.TextBox1.Tex t = Me.txtFileSourc e.Text.Substrin g(CType(Me.txtF ileSource.Text. LastIndexOf("\" ), Integer) + 1)
          End If
          End Sub

          Private Sub butBrowseDestin ation_Click(ByV al sender As System.Object, ByVal e As System.EventArg s) Handles butBrowseDestin ation.Click
          Dim bResult As DialogResult

          If Me.chkFileOrDir .Checked Then
          'Copy all directory
          bResult = Me.FolderBrowse rDialog1.ShowDi alog
          'If cancel button was cicked return to main form
          If bResult = Windows.Forms.D ialogResult.Can cel Then Exit Sub
          'Put the directory name on the text box
          Me.txtDirDestin ation.Text = Me.FolderBrowse rDialog1.Select edPath.ToString ()
          Else
          'Copy just a file
          bResult = Me.FolderBrowse rDialog1.ShowDi alog
          'If cancel button was cicked return to main form
          If bResult = Windows.Forms.D ialogResult.Can cel Then Exit Sub
          'Put the directory name on the text box
          Me.txtDirDestin ation.Text = Me.FolderBrowse rDialog1.Select edPath.ToString ()
          End If
          End Sub

          Private Sub chkFileOrDir_Ch eckedChanged(By Val sender As System.Object, ByVal e As System.EventArg s) Handles chkFileOrDir.Ch eckedChanged
          If Me.chkFileOrDir .Checked Then
          Me.chkFileOrDir .Text = "Copy Entire Directory"
          'Hide the file name
          Me.TextBox1.Vis ible = False
          Me.lblNewFileNa me.Visible = False
          Me.butCopy.Text = "Copy Directory"
          Else
          Me.chkFileOrDir .Text = "Copy Just One File"
          'Show the file name
          Me.TextBox1.Vis ible = True
          Me.lblNewFileNa me.Text = True
          Me.butCopy.Text = "Copy File"
          End If
          End Sub

          Private Sub subCopyDir(ByVa l sOri As String, ByVal sDes As String)
          Dim sFile As String

          'copy all the files
          For Each sFile In Directory.GetFi les(sOri)
          File.Copy(sFile , sDes & "\" & sFile.Substring (sFile.LastInde xOf("\") + 1))
          Application.DoE vents()
          Next

          End Sub

          Private Sub subCopyFil(ByVa l sOri As String, ByVal sDes As String)
          Try
          File.Copy(sOri, sDes)
          Application.DoE vents()
          Catch ex As Exception
          MessageBox.Show ("Error: " & ex.Message)
          End Try
          End Sub

          Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
          'hide progressbar
          Me.ProgressBar1 .Visible = False
          End Sub
          End Class


          /[CODE]

          Comment

          • xinariscy
            New Member
            • Sep 2008
            • 14

            #20
            lee123, you can use Timer to make your life easier (you may already know this), with a pseudo-progressbar

            1)Drag a Timer control to your form. Set the interval e.g. to 500 and enable = false

            2) Modify your code

            [PHP]Private Sub cmdCopy_Click()
            Dim fso As New Scripting.FileS ystemObject
            Dim fld As Folder
            cmdCopy.Caption = "Copying Folder!"
            Set fld = fso.GetFolder(t xtSourceOfFolde r)
            fld.Copy (txtDestination OfFile)
            Timer1.enabled = True
            End Sub[/PHP]


            [PHP]Private Sub Timer1_Timer()
            ProgressBar1.Va lue = ProgressBar1.Va lue + Timer1.Interval / 10
            If (ProgressBar1.V alue = 100) Then
            Label1.Caption = "Copying Folder Is Completed!"
            Beep
            txtSourceOfFold er.Text = ""
            txtDestinationO fFile.Text = ""
            cmdExit.Enabled = True
            Timer1.Enabled = False
            End If
            End Sub[/PHP]

            Comment

            • lee123
              Contributor
              • Feb 2007
              • 556

              #21
              well thank you rpicilli for that i will give it a try and your right about reading if you have the time. but going to school at night and working through the day is hard work but thank you for your help through this.

              and xinariscy, your code looks intersting and simple so i am going to give this a try as well.

              lee123

              Comment

              • smartchap
                New Member
                • Dec 2007
                • 236

                #22
                Dear Xinariscy
                In your program there is no use of Progress Bar as it Increments only after the folder has been copied, i.e. value of progress bar is not dependent on size of folder. Yes it is dependent on Timer interval which makes it slow or fast. So I think it will not solve the problem lee123 has.

                Comment

                • lee123
                  Contributor
                  • Feb 2007
                  • 556

                  #23
                  hey smartchap your right when i tried this way the folder copied and then at the end the progressbar worked strange.

                  lee123

                  Comment

                  • xinariscy
                    New Member
                    • Sep 2008
                    • 14

                    #24
                    smartchap you are right! That's why I say it's only a pseudo-progress bar. It's only for the eyes. This is absolutely no professional!.. .

                    Comment

                    • smartchap
                      New Member
                      • Dec 2007
                      • 236

                      #25
                      I have tried code provided by tristanlbailey and its working fine (after some modifications). After I write a simple program will post it.

                      Comment

                      • smartchap
                        New Member
                        • Dec 2007
                        • 236

                        #26
                        First of all sorry for the delay. Please see my submission at following URL:

                        http://www.planet-source-code.com/vb/scripts/ShowCode.asp?tx tCodeId=71156&l ngWId=1

                        It has full featured copying of folder to another folder with almost no bugs. If u find any bug please let me know remove it.

                        Dear lee123 I have also answered for ur animation post (for progress bar). In a similar way u can solve that problem also.

                        Comment

                        • smartchap
                          New Member
                          • Dec 2007
                          • 236

                          #27
                          Dear lee
                          I think u must have downloaded CopyFolder_PBar from planet source code (PSC). If it helped u please reply and vote the submission by scrolling the screen of the code )below Download Code) in PSC.

                          Comment

                          • lee123
                            Contributor
                            • Feb 2007
                            • 556

                            #28
                            no i got the code from a book i have and it was different than what i have posted (made a little adjustments on it) i thought it would work but didn't.

                            lee123

                            Comment

                            • smartchap
                              New Member
                              • Dec 2007
                              • 236

                              #29
                              Dear lee
                              U can download my code and it works fine. However, which code u have from book and is not working, please upload here with the problem u are facing so that I will try to resolve the problem.

                              Comment

                              • lee123
                                Contributor
                                • Feb 2007
                                • 556

                                #30
                                hello, i have posted my project on the web so you can see what it looks like, it is different from yours and i have tried yours and it works great but there are things on mine that i don't know where to put your code if you want to see it go to this address or click

                                here:

                                the code i tried to use is on the "progressba r post"

                                Code:
                                For P = 1 to 100 
                                       Progressbar1.value = P 
                                              For x = 1 to 100                
                                       Next x 
                                Next P
                                how can i put this kinda code for the progressbar with the timer with my code on the web page

                                lee123

                                lee123

                                Comment

                                Working...