Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

timer trouble

Posted on 2000-03-26
6
Medium Priority
?
229 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
[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
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 300 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
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 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

Industry Leaders: 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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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 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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

604 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