Solved

Figuring out Timer Interval for Progress Bar

Posted on 2004-08-23
8
317 Views
Last Modified: 2010-05-03
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!
0
Comment
Question by:jcreswell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 11876324
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.
0
 
LVL 18

Expert Comment

by:JR2003
ID: 11876456
What is it you're trying to do?
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 11877392
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:jcreswell
ID: 11877495
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!
0
 
LVL 7

Expert Comment

by:Burbble
ID: 11877578
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
0
 
LVL 1

Author Comment

by:jcreswell
ID: 11877759
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?
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 11878194
What are the values in Liq1_Amount thru Liq2_Amount measured in?  Milliseconds?  Seconds?

What is their format? Whole numbers? Fractions?

Idle_Mind
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 11878222
The following worked well for values measured in whole seconds.  The progressbar had the default min of 0 and max of 100.

Regards,

Idle_Mind

Option Explicit

Private Sub Command1_Click()
    Dim i As Integer
    Dim L As Label
    Dim TotalTime  As String
   
    TotalTime = "0"
    For i = 1 To 5
        Set L = Form1("Liq" & i & "_Amount")
        TotalTime = Val(TotalTime) + Val(L)
    Next
   
    ProgressBar1.Value = 0
    pbtimer.Interval = Val(TotalTime) / 100 * 1000 ' divide time into 100 slices and convert to milliseconds
    pbtimer.Enabled = True
End Sub

Private Sub pbtimer_Timer()
    If ProgressBar1.Value < 100 Then
        ProgressBar1.Value = ProgressBar1.Value + 1
    End If
    If ProgressBar1.Value = 100 Then
        pbtimer.Enabled = False
        MsgBox "Done!"
    End If
End Sub
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question