Results 1 to 10 of 10

Thread: How to code progressbar

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    How to code progressbar

    I know the total length of the data and how many bytes are being sent per each chunk. How do I relate this info to a progressbar showing each progress as it occurs


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  2. #2

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: How to code progressbar

    OK, that works fine but I have a secondary problem that I didn't realize until I used your suggestion.

    I need to show progressbar during the time it takes to load the data prior to it being sent plus the time it takes to send the data.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  4. #4
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: How to code progressbar

    It's probably better to use a percentage.

    The Total Data will be (Amount of Data to Load + Amount of data to Send)

    During the loading process the increment will be (Amount of data loaded so far * 100)/Total Data and during the sending process (Amount of data sent so far * 100) / Total Data. Your ProgressBar Max property will be 100

  5. #5
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: How to code progressbar

    In addition to Doogle's idea, I used to make my own progress bar using shape controls. Each completion increment was a shape that I stacked horizontally. Initially all the shapes were invisible and as an increment was completed, the shape became visible. When all the shapes were visible, the processing was complete.

    The shapes could have different colors, one for each increment or better yet, one for each collection of similar increments (such as red shapes for loading data and blue shapes for sending data). As the processing moved from one collection or phase to the next, I also changed the caption of a label to explain what was going on, usually ending the label caption with three periods.

    Note that an approximate percentage indicator on a label is also a good idea. Real time indicators are always governed by the speed of a user's machine, so they will seldom be accurate from one one computer to the next. I recently updated protection software that kept restarting a new progress bar from phase to phase, and that seemed misleading. There were three or four phases, so you really had little indication of how long the processing was actually going to take. To me, that was rather poor design.
    Doctor Ed

  6. #6
    Banned
    Join Date
    Nov 2012
    Posts
    1,171

    Re: How to code progressbar

    this will help
    http://www.hackcommunity.com/Thread-...tats-with-Inet

    add these code were all your chunks being processed ul get the idea

  7. #7
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: How to code progressbar

    Quote Originally Posted by jmsrickland View Post
    I need to show progressbar during the time it takes to load the data prior to it being sent plus the time it takes to send the data.
    Quote Originally Posted by Doogle View Post
    It's probably better to use a percentage.
    @Doogle:
    That's not going to help solving what OP is asking. Whether you use percentage or a+b result will be the same and it will only cover second part (sending data).

    @jmsrickland:
    How do you get/load data?

  8. #8
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: How to code progressbar

    Yeah - my preference for ProgressBars is %age, but my calculation was wrong in any case, the 'Sending Data' part is incorrect and should have been (Amout of data loaded + Amount of data sent so far) * 100 / Total Data.

    So, if OP is loading 4Mb and sending 1Mb, the Total Data will be 5Mb, once the data is loaded, the ProgressBar will be 80% of the way to completion (4*100/5). When the 1Mb has been transmitted the ProgressBar will be at (4+1)*100/5 = 100% Obviously the speed at which the progress is displayed will depend upon the efficiency of the loading and sending methods together with the sampling interval.

    There will be a potential issue if OP mixes Apples and Pears. For example, if the Loading of data is measured in records and the sending is measured in bytes, using %age or a+b will result in a non-linear progress.

    EDIT: Just realised that I might have misunderstood the question. I had read it as there are 2 distinct processes, vis: (1) Loading the Data followed by (2) Sending the data. (i.e. nothing is sent until all the data is loaded, rather than; load some data, send some data, load some more, send some more etc.)

    EDIT1: (a+b methodology as opposed to %age)

    2 Processes: Read all then send (Pseudo Code)
    Code:
    Len = LOF(File)
    ProgressBar.Max = Len + BytesToSend
    ProgressBar.Visible = True
    Len1 = 0
    Do
        Read Record
        Len1 = LengthOfRecord + Len1
        Process Record
        ProgressBar.Value = Len1 
    Loop Until EOF(File)
    Len1 = 0
    Do
        Send Some Data
        Len1 = NumberOfBytesSent + Len1
        ProgressBar.Value = (Len + Len1) 
    Loop Until Len1 = BytesToSend
    ProgressBar.Visible = False
    1 Process: Read some, send some (Pseudo Code)
    Code:
    ProgressBar.Max = BytesToSend
    ProgressBar.Visible = True
    Len1 = 0
    Do
        Read Record
        Process Record
        Send Data
        Len1 = NumberOfBytesSent + Len1
        ProgressBar.Value = Len1
    Loop Until EOF(File)
    ProgressBar.Visible = False
    Of course, in both cases BytesToSend must be known before the ProgressBar is updated.
    Last edited by Doogle; May 7th, 2013 at 09:00 AM.

  9. #9
    Banned
    Join Date
    Nov 2012
    Posts
    1,171

    Re: How to code progressbar

    Quote Originally Posted by Doogle View Post
    Yeah - my preference for ProgressBars is %age, but my calculation was wrong in any case, the 'Sending Data' part is incorrect and should have been (Amout of data loaded + Amount of data sent so far) * 100 / Total Data.

    So, if OP is loading 4Mb and sending 1Mb, the Total Data will be 5Mb, once the data is loaded, the ProgressBar will be 80% of the way to completion (4*100/5). When the 1Mb has been transmitted the ProgressBar will be at (4+1)*100/5 = 100% Obviously the speed at which the progress is displayed will depend upon the efficiency of the loading and sending methods together with the sampling interval.

    There will be a potential issue if OP mixes Apples and Pears. For example, if the Loading of data is measured in records and the sending is measured in bytes, using %age or a+b will result in a non-linear progress.

    EDIT: Just realised that I might have misunderstood the question. I had read it as there are 2 distinct processes, vis: (1) Loading the Data followed by (2) Sending the data. (i.e. nothing is sent until all the data is loaded, rather than; load some data, send some data, load some more, send some more etc.)

    EDIT1: (a+b methodology as opposed to %age)

    2 Processes: Read all then send (Pseudo Code)
    Code:
    Len = LOF(File)
    ProgressBar.Max = Len + BytesToSend
    ProgressBar.Visible = True
    Len1 = 0
    Do
        Read Record
        Len1 = LengthOfRecord + Len1
        Process Record
        ProgressBar.Value = Len1 
    Loop Until EOF(File)
    Len1 = 0
    Do
        Send Some Data
        Len1 = NumberOfBytesSent + Len1
        ProgressBar.Value = (Len + Len1) 
    Loop Until Len1 = BytesToSend
    ProgressBar.Visible = False
    1 Process: Read some, send some (Pseudo Code)
    Code:
    ProgressBar.Max = BytesToSend
    ProgressBar.Visible = True
    Len1 = 0
    Do
        Read Record
        Process Record
        Send Data
        Len1 = NumberOfBytesSent + Len1
        ProgressBar.Value = Len1
    Loop Until EOF(File)
    ProgressBar.Visible = False
    Of course, in both cases BytesToSend must be known before the ProgressBar is updated.

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: How to code progressbar

    Well I guess I am not going to be able to show a progress on the loading of the data as it blocks further execution until all data has been loaded. I'm reading binary data into an array like this

    Code:
      '
      '
     ProgressBar1.Value = 0
    
     Open FilePath For Binary As #1
     
     DataLength = LOF(1)
     
     ProgressBar1.Max = DataLength
     
     ReDim ByteArray(LOF(1) - 1)
     
     Get #1, , ByteArray        '<---- Cannot show progress because this blocks
     
     Close #1
     
     SendByteArray
      '
      '


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

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