Link to home
Start Free TrialLog in
Avatar of jcreswell
jcreswell

asked on

Figuring out Timer Interval for Progress Bar

I'm having a really hard time wrapping my brain around this one.

I have a button, a timer, and a progress bar.

Dim L As Label
TotalTime = "0" 'set the variable that tracks the total required time to 0
For i = 1 To 5
    Set L = Form1("Liq" & i & "_Amount")
    TotalTime = Val(TotalTime) + Val(L) 'for each value, add it to the total time required
Next
pbtimer.Interval = Val(TotalTime) 'PROBLEM LINE - this is where I think the error lies
pbtimer.Enabled = True

Then the timer code is

Private Sub pbtimer_Timer()
If ProgressBar1.Value = 100 Then
 Exit Sub
Else
 ProgressBar1.Value = ProgressBar1.Value + Val(TotalTime) 'add one percent to the progress bar
End If

So, let's say I need .99 total seconds to complete the task at hand.  How do I set the timer interval to fire off every one hundreth of the required time?  Times 1000 for the timer's interval?  How does the percent (1/100) of what I want to do and the 1/1000 = one second property of the timer both interact?  See my confusion?   (...maybe this is more a math question than a VB question?)

Thanks!
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

The usual way is to divorce the checking time from the data.
You can set the .Max value to the expected maximum value, and then at each update, possible timer-dependent, set the Value to the current value of whatever is being measured.
Avatar of JR2003
JR2003

What is it you're trying to do?
I agree with JR2003.  Please explain a little more about how your program should work.

Can't quite make sense of the code you posted...  

=)
Idle_Mind
Avatar of jcreswell

ASKER

TotalTime is the total amount of time needed to reach 100% on the progress bar.

I cannot figure out how to set the progressbar.max property or the pbtimer.interval properties to cause the progress bar to take 'totaltime' amount of time to reach 100%

I am confused over the interplay between having to specify the "amount" to add to the progress bar per timer cycle in a Percent (out of 100) and the interval of the timer (where 1 second = 1000).

I hope that clears some up, let me know if you need more info!
Couldn't you just set the ProgressBar's .Max property to 1000 to avoid confusion? :-)

I am curious, what does this line do?

    Set L = Form1("Liq" & i & "_Amount")

-Burbble
That line enables me to loop through my fields, they are named Liq1, Liq2, Liq3, and so on.  L holds the name of that field so that the value can be pulled and added to "TotalTime."  The fields as a whole add up to the sum of the amount of time the progress bar needs to be going from 0% to 100%.

I tried setting the progressbar max to 1000, it still escapes me how these all work together.  Could you post example code of how this might work, or a description?
What are the values in Liq1_Amount thru Liq2_Amount measured in?  Milliseconds?  Seconds?

What is their format? Whole numbers? Fractions?

Idle_Mind
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial