Solved

timer trouble

Posted on 2000-03-26
6
180 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
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
Comment Utility
wpsjr1 - I got mine chewed out yesterday, don't feel bad. LOL ;>)
0
 
LVL 1

Expert Comment

by:rskathait
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now