Results 1 to 6 of 6

Thread: VB Progress Bar

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    South Africa
    Posts
    113

    Cool VB Progress Bar

    Hi all,
    I have an App that takes about a minute to run, and stuff gets done in the background that you cant see. what should I do while the app is running to let the user know that it is running. The VB progress bar is an option but I have no idea how it works. i.e. how does it know how much % is complete if it doesnt know how long it will take altogether??

    also, is there anyother idea any of yous have. I thought of flashing text saying working...but How do i get the label to flash?


    Thanks all
    You are living a pacifist dream, and if you dreaming it means you sleeping and you should damn well wake up!

  2. #2
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    with the progress bar control you give it a min and max value, which you would usually set to 0 and 100.

    then you send it a value at design time between those values and it does the rest for you.

    lets say you were in a loop that was going to loop 678 times.

    before the loop set the progress bar to 0 and set its max to 678.

    then at the end of each loop, set the progress bar to which ever loop counter your on.

    example:

    VB Code:
    1. progress.min =0
    2. progress.max = 678
    3. progress = 0
    4.  
    5.  
    6. for i = 1 to 678
    7.     'put your processing code here
    8.     progress = i
    9. next i

    doddle.
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  3. #3
    Lively Member
    Join Date
    Sep 2001
    Location
    Berkshire
    Posts
    121
    Progress bars are difficult to use well! You may have noticed that microsoft struggle with it continuously!

    It means that you have to design your code with lots of loops in it. Which sounds okay in theory, but is quite hard when you have a bit of code that shells something in the program, which jams up all the CPU usage!

    Like Darre1 said, you have to define a maximum and a minimum. If you know that your code is going to loop 612 or whatever times, then you can hard code it like that. However, a better way is to do it on the fly, Max = Len(Str ..... etc. You get what i mean. Calculate the max and min depending on what your program has to do.

    Then, look for all available opportunities to update the progress bar. You will probably find you have more than one loop, which results in that annoying, completion of the progress bar, and then restarting it again! Unfortunately, this is largely unavoidable, as long as you don't know how long your code will actually take to execute.

    To be fair, many people are used to pointless progress bars! Seeing something happen is much better than thinking your program has crashed the computer! Hope this helps.

    Darren
    "Put that thing back where it came from or so help me. So help me, so help me, and cut."

  4. #4
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    If you can't control the progress bar accurately, it might be better to use a different display.
    Show an animated GIF or something else (like a file being copied to the wastebin continuously).

  5. #5
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    i like the idea of an animated gif!

    but like having a progress bar, having something to keep the user's attention and informing them that there machine hasn't crashed, bear in minf that it also slows down your processing.
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  6. #6
    Staifour
    Guest
    well
    if you are saying that your program only need about a minute to do what it has to do, idon't think that the user will really care that the progress bar i EXACTLY at the point in which the code is so i have two ideas:

    Firstly :
    look at the code of your program and try to slice it into a big number of slices (maybe 100) so that each slice takes about the same time as the other slices
    set the progress bars' min to 0 and max to the number of slices (100 in my example)
    now at the begining of the code add
    VB Code:
    1. ProgressBar.Value = 0
    (where ProgressBar is the name of your progress bar)
    and after each slice of code add
    VB Code:
    1. ProgressBar.Value = ProgressBar.Value + 1
    2. DoEvents
    (if you find this code is slow delete DoEvents)
    and if you find that a slice takes twice time of each of the other slices you can put after this slice
    VB Code:
    1. ProgressBar.Value = ProgressBar.Value + 2
    2. DoEvents
    and soo on ...

    Secondly:
    try to find out exactly how much of time your program takes
    at the declarations add the declaration of GetTickCount and add
    VB Code:
    1. Dim IntTick
    2. Dim TimeTaken
    3. Dim AllTime
    at the begining of your code add
    VB Code:
    1. IntTick = GetTickCount
    2. AllTime = 'Put here the time your application needs to load in milliseconds
    now in your code add each 10 lines (As example)
    VB Code:
    1. TimeTaken = GetTickCount - IntTick
    2. ProgressBar.Value = TimeTaken / AllTime

    hope that this will help

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