Sub Class_Globals
Dim T As Timer
Type NameAndTimeLong (Name As String, TimeLong As Long) 'The name of the timer and the long (milliseconds) of when its due
Dim myTimers, deletes As List
Dim tt As Boolean
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
T.Initialize("T", 1000) 'obviously after testing you would reduce this number to give it a higher resolution
myTimers.Initialize ' and you'd remove all the logging and the Tick-Tocking etc. :)
deletes.Initialize
T.Enabled = True
End Sub
Sub T_tick
Try
If tt = True Then
Log("tick")
tt = False
Else
Log("tock")
tt = True
End If
For a = 0 To myTimers.Size -1
Dim NameTime As NameAndTimeLong
NameTime = myTimers.Get(a)
If NameTime.TimeLong < DateTime.Now Then
Log("timer " & NameTime.Name)
CallSub2(BTComms, "SendMsgBluetooth", NameTime.Name)
deletes.Add(a)
End If
Next
For a = 0 To deletes.Size -1
myTimers.RemoveAt(deletes.Get(a)) 'can't be removing list items while iterating through the list :)
Next
deletes.Clear
Catch
myTimers.Clear
deletes.Clear
Log("T_tick")
End Try
End Sub
Sub Add(inString As String)
Log("Adding " & inString)
Dim s As String = inString.SubString(1).Trim
If IsNumber(s) = True Then
Dim NameTime As NameAndTimeLong
Log("it is the number " & s)
NameTime.Name = inString.Trim
NameTime.TimeLong = s + DateTime.Now
myTimers.Add(NameTime)
Log("time now is " & DateTime.Time(DateTime.Now))
Log(DateTime.Time(NameTime.TimeLong))
Log(myTimers.Size & " timer entries")
T.Enabled = True
End If
End Sub