Solved

timer trouble

Posted on 2000-03-26
6
191 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

947 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

20 Experts available now in Live!

Get 1:1 Help Now