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!

Multi timer problem 1

Status
Not open for further replies.

Scouseman

Technical User
Mar 25, 2003
22
US
Hi

I have searched the board looking for a solution to my multi timer problem but do not seem to be able to get it to work. What I am tring to do is read the contents of a .dll file (which is a custom programmed dll which stores global variables in it). I need to read the dll every 7 minutes between 8.00am an 5.00pm for the duration of 10 seconds then stop reading the dll, during the 10 seconds it must read the dll every second so it will read it 10 times.

I am getting very confused on how to achieve this. I think I need to setup 2 timers. 1 timer that starts the read routine every 7 mins and one that times the 10 second read routine and read the .dll every 1 second.

Thankyou for all your help

Scouse
 
Set your Timer1 with an Interval of 60000 (1 minute). In the Timer1 event use a Static variable and increment it on each call to the routine until it reads 7. When it reads 7 enable Timer2 with an Interval of 1000 (1 second). In the Timer2 event do your read routine, and increment your Timer2 static variable up to 10, when you disable Timer2.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Hi


Thanks for your help it is much appreciated (also sorry for the misunderstanding), the only problem I would have with your solution is that, if the program was stopped or crashed part way the day then restarted the timer would be out of syncronisation. Is there anyway I can get around this problem. Also I need timer 2 to kick on the 10 seconds of the 7 minutes (so for example timer 2 would kick in at 08:06:50 am and at 08:13:50am and at 08:20:50).

Any help would be most appreciated

Regards

Scouse
 
Hi

I have come up with some code you my timer problem which seems to work, the only thing which is bothering is if the program crashes or I switch the program off the timer looses syncronisation as the code reads the file every 7 mins from 08:06:50. The code I have upto now is as follows:

Public Const StartTime As Date = "8:06:55 AM"
Public Const StopTime As Date = "5:00:00 PM"
Public Const PollInteral As Long = 420

Private Sub Form_Load()
Timer1.Interval = 10
End Sub

Private Sub Timer1_Timer()
If (Time >= StartTime) And (Time <= StopTime) Then
Dim NextPoll As Long
Static Multiplier As Long

Multiplier = Multiplier + 1
NextPoll = (Multiplier)* PollInteral

If Time >= StartTime + (NextPoll / 86400#) Then
'My work
Else
DoEvents
End If
End sub

Does anyone knoe of a way how I could set it up so that it is easily sycronised what ever time I start the interface?

Thanks

Scouse
 
Check if a certain file exists at Form_Load(), then if it doesn't, store the time in a file at Form_Unload(). If it does, load the time from the file and subtract it from the current time. This way you can find out how much time has passed since the last time the program was run, and make calculations accordingly.
Crystalinity
 
Just for the hell of it:
[tt]
Option Explicit

Private Sub Form_Load()
Timer1.Interval = 1000
Timer1.Enabled = True
Timer2.Interval = 1000
Timer2.Enabled = False
End Sub

Private Sub Timer1_Timer()
Dim Interval As Long
If Timer >= 8 * 60 * 60 And Timer <= 17& * 60 * 60 Then
Interval = Fix(Timer) - (8 * 60 * 60 - 10)
Interval = Interval Mod 420
If Interval = 0 Then
' Trigger 10 second timer
Debug.Print &quot;Activating at: &quot; & Time
Timer2.Enabled = True
End If
End If
End Sub

Private Sub Timer2_Timer()
Static Enabled As Long

Enabled = (Enabled + 1) Mod 10

If Enabled = 0 Then Timer2.Enabled = False

Debug.Print &quot;Tick: &quot; & Time


End Sub
 
Hi strongm

Thanks for the code it is much appreciated that is just what I needed

Scouse
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top