View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
FinnBarr FinnBarr is offline
external usenet poster
 
Posts: 13
Default Timer Procedures

Hi All

Im developing a spreadsheet that captures live feeds. I want to
capture the data at one second intervals max and record different
markets to a separate worksheet. I've got the basics sorted, I just
need to get a repeating timer to record and its set.

Ive read through some of the posts for the above and came acrss Chip
Pearsons site detailing two alternative timer procedures. I tried them
both by copying and pasting from the web page.

I tried the Windows API call first as it can be set to milliseconds.
It was working nicely for 20 minutes but, as Chip points out, its
unstable and caused my machine to fall over, losing all the recorded
data in the process. But at least I know that the rest of my code
works ok.

I tried the OnTime procedure next and ran it from the VBE editor but
it only makes one call and then stops. I assigned it to a menu item
and that doesnt even make call. I cant understand why it wont work.
Help please.

Below is a copy of the code which, as you can see has been lifted
straight from Chips page.

Public RunWhen As Double
Public Const cRunIntervalSeconds = 1 ' one second
Public Const cRunWhat = "UpdateMarkets" ' the name of the procedure
to run

Sub StartTimer()

RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)

Application.OnTime EarliestTime:=RunWhen, Procedu=cRunWhat,
Schedule:=True

End Sub

Sub StopTimer()

On Error Resume Next

Application.OnTime EarliestTime:=RunWhen, Procedu=cRunWhat,
Schedule:=False

End Sub

Sub UpdateMarkets()

' Ive omitted a select case structure here (which
determines how many markets require data capture)_
to save space.

Call StartTimer

End Sub