Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timing Problem 3

Status
Not open for further replies.

anastasia

Programmer
Dec 13, 2000
111
GB
Hi,

I am wanting to start a timer going once a form is loaded for 3 mins, after the 3 mins is up a Msg Box will be displayed. After I want the timer to start timing again another 3 mins and then display another MsgBox. I need this to happen roughly 5 times throughout the application I am creating.

I have done this type of thing before but only in MS word using the following code:

Application.OnTime when:=Now + Timevalue ("00:15:00"), Name:= "ProjectCompany.Module1.Macrostart".

The code when run did so for 15 mins and then ran the code within the MacroStart. this code is for word is their any code similar but for use in Visual Basic.

Thanks

A
 
Create a timer control, with interval of 1000 ' 1 second and use it like this

Code:
Option Explicit
dim varCount as Integer

varCount = 0

Sub Timer1()

 varCount = varCount +1  

If varCount >= 180 then       'the timer fires every second
   whatever                   'so count them and when it
end if                        'gets to 180 (3mins) do something

End Sub

*****************************************
May the Code Be With You...[lightsaber]
----------
x50-8 (X Fifty Eigt)
 
You can also just set the timer
Code:
.Interval
property to 180,000 (3 min). You will also need a variable to track the number of times the event fires. Only allow the code to fire 5 times.

To continue with what x508 posted.

Code:
Sub Timer1_Timer()
  Static i as Integer
  If i <= 4 then           
    MsgBox &quot;Timer&quot;
    i= i + 1                     
  end if                        
End Sub

This way you only fire the timer event every three mins and only increment the counter as long as it is needed.


Take Care,

zemp

&quot;If the grass looks greener... it's probably because there is more manure.&quot;
 
Sorry, but the maximum you can set the interval property to is 65,536.


- B
 
True, then set the
Code:
.Interval
to 60,000 (1 min) and change the code to this.

Code:
Private Sub Timer1_Timer()
   Static i As Integer, j As Integer
   
   If i < 5 Then 'allow to run only five times 
      j = j + 1
      If j = 3 Then  'run every three mins
         MsgBox &quot;Timer&quot;
         i = i + 1
         j = 0
      End If
   End If
End Sub


Take Care,

zemp

&quot;If the grass looks greener... it's probably because there is more manure.&quot;
 
Thanks Guys for your reply.
The code above works perfect problem solved
Thank you very much

 
Plsr

*****************************************
May the Code Be With You...[lightsaber]
----------
x50-8 (X Fifty Eigt)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top