Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdTimer - Cache remote workbook #67

Open
sancarn opened this issue Feb 9, 2023 · 0 comments
Open

stdTimer - Cache remote workbook #67

sancarn opened this issue Feb 9, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@sancarn
Copy link
Owner

sancarn commented Feb 9, 2023

Currently our code uses 1 workbook per timer, which is crazy slow. This is currently declared as "not really an issue" because requiring more than 1 timer is likely rare(?).

However if a work around was desired we could instead:

  1. Cache the workbook
  2. Use the AddTimer() method of below:
Private Type Timer
  current as long
  frequency as long
  id as string
End Type
Private Timers() as Timer
Private Const MAX_TIME as Long = 1000000
Private Const MIN_TIME as Long = 10

Sub AddTimer(ByVal iMilliseconds as long, ByVal id as string)
  if iMilliseconds > MAX_TIME then iMilliseconds = MAX_TIME
  if iMilliseconds < MIN_TIME then iMilliseconds = MIN_TIME
  On Error Resume Next: iNext = ubound(Timers)+1: On Error GoTo 0
  Redim Timers(0 to iNext)
  With Timers(iNext)
    Timers.current = 0
    Timers.frequency = iMilliseconds
    Timers.id= id
  End With
End Sub

Sub MainLoop()
  set r = Sheet1.Cells(1,1)
  While True
    For each timer in Timers
      timer.current = timer.current + 1
      if timer.current mod timer.frequency = 0 then 
        r.Value = id
        timer.current = 0 'saves having to deal with overflows
      end if
    next
    Doevents
    Sleep 1
  Wend
End Sub
  1. OnChange use the id = Target.Value and lookup id in a dictionary to find callback. Also pass id to Tick event.

This can handle multiple timers each added at different times. Unfortunately as new timers are added the whole class slows down, but perhaps this is ok.

@sancarn sancarn added the enhancement New feature or request label Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Feature Request/Unknown requirement
Development

No branches or pull requests

1 participant