Solved

timer trouble

Posted on 2000-03-26
6
200 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

816 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

11 Experts available now in Live!

Get 1:1 Help Now