Solved

timer trouble

Posted on 2000-03-26
6
212 Views
Last Modified: 2010-05-02
i'm trying to get my timer to stop after 30 seconds, but i'm not sure how to do it.
0
Comment
Question by:slippery_finger
6 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2659100
one simple way would be to set a counter variable (i) and if your timer interval is one second then

Sub Timer1()
If i = 30 then timer1.enabled = false
else i = i + 1
end sub

0
 
LVL 3

Expert Comment

by:Foyal
ID: 2659292
If you also need the timer to run at a higher resolution (less than 1000ms) then try this in the timer procedure:

Option Explicit

'declare counter    
Dim CountDownTicks As Integer

'declare test string
Dim strTestTime as String

Private Sub Form_Load()

    'initialize counter
    CountDownTicks = 0

    'initialize test string
    strTestTime = Format(Now, "hh:mm:ss")

End Sub

Private Sub tmrTime_Timer()    

    'check to see if a second has passed
    If strTestTime <> Format(Now, "hh:mm:ss") then
        strTestTime = Format(Now, "hh:mm:ss")
        'if so count it
        CountDownTicks = CountDownTicks + 1
    End If

    'when desired value is reached disable timer
    'and re-initialize counter for next use
    If CountDownTicks = 30 then
        tmrTime.Enabled = False
        CountDownTicks = 0
    End If

End Sub


0
 
LVL 3

Accepted Solution

by:
wpsjr1 earned 75 total points
ID: 2659343
This will do the trick if you need just one execution of the timer

Option Explicit

Private Sub Form_Load()
  Timer1.Interval = 30000
End Sub

Private Sub Timer1_Timer()
  Debug.Print "Time is up!"
  Timer1.Enabled = False
End Sub
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 28

Expert Comment

by:AzraSound
ID: 2659356
wpsjr1,
Being that you are new here I wish to inform you of a certain etiquette at this site.  Just post comments to these questions.  The person asking the question can accept any comment at any time as an answer.  By anwering the question you lock the question and move it to the less traffic area and may not allow better solutions to possibly come about (due to the fact most experts dont look at the locked questions).  

Regards
0
 
LVL 3

Expert Comment

by:Foyal
ID: 2659437
wpsjr1 - I got mine chewed out yesterday, don't feel bad. LOL ;>)
0
 
LVL 1

Expert Comment

by:rskathait
ID: 2659574
Hi,

(It's a second proposed answer)

It's so simple
Private Sub Form_Load()
    Timer1.Interval = 30000
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
    MsgBox "Hi"
    Timer1.Enabled = False
End Sub

The trick by AzraSound will wotk fine if you want to check for more then 65655 milliseconds. WIll need some logic.

For Foyal's comment, remember that the least count for VB timer is 58-59 milliseconds.

If you want more flexible timers then go for code based timers using APIs

enjoy,
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

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 trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

726 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