|
-
Jan 31st, 2002, 05:07 AM
#1
Thread Starter
Lively Member
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!
-
Jan 31st, 2002, 05:13 AM
#2
Bouncy Member
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:
progress.min =0
progress.max = 678
progress = 0
for i = 1 to 678
'put your processing code here
progress = i
next i
doddle.
-
Jan 31st, 2002, 05:28 AM
#3
Lively Member
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."
-
Jan 31st, 2002, 05:49 AM
#4
Frenzied Member
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).
-
Jan 31st, 2002, 06:12 AM
#5
Bouncy Member
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.
-
Jan 31st, 2002, 07:17 AM
#6
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
(where ProgressBar is the name of your progress bar)
and after each slice of code add
VB Code:
ProgressBar.Value = ProgressBar.Value + 1
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:
ProgressBar.Value = ProgressBar.Value + 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:
Dim IntTick
Dim TimeTaken
Dim AllTime
at the begining of your code add
VB Code:
IntTick = GetTickCount
AllTime = 'Put here the time your application needs to load in milliseconds
now in your code add each 10 lines (As example)
VB Code:
TimeTaken = GetTickCount - IntTick
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|