Class Name TimeSwitch
B4X:
'time switch
Sub Class_Globals
Type HourSettings(q1 As Boolean,q2 As Boolean,q3 As Boolean,q4 As Boolean)
Private DaySettings(24) As HourSettings '0 to 23
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
Clear
End Sub
public Sub Clear
Dim h As Int
For h = 0 To 23
DaySettings(h).q1 = False
DaySettings(h).q2 = False
DaySettings(h).q3 = False
DaySettings(h).q4 = False
Next
End Sub
public Sub EveryHourOnce
Dim h As Int
For h = 0 To 23
DaySettings(h).q1 = True
DaySettings(h).q2 = False
DaySettings(h).q3 = False
DaySettings(h).q4 = False
Next
End Sub
public Sub Every4HoursOnce
Dim h As Int
For h = 0 To 23 Step 4
DaySettings(h).q1 = True
DaySettings(h).q2 = False
DaySettings(h).q3 = False
DaySettings(h).q4 = False
Next
End Sub
public Sub IsOn(Hour As Int,Minute As Int) As Boolean
Hour = Hour Mod 24
Minute = Minute Mod 60
Dim ThisHour As HourSettings
ThisHour = DaySettings(Hour)
If Minute >= 0 And Minute < 15 Then
If ThisHour.q1 = True Then Return True
else if Minute >= 15 And Minute < 30 Then
If ThisHour.q2 = True Then Return True
else if Minute >= 30 And Minute < 45 Then
If ThisHour.q3 = True Then Return True
else if Minute >= 45 And Minute < 60 Then
If ThisHour.q4 = True Then Return True
End If
Return False
End Sub
query usage
B4X:
If TimeSwitch1.IsOn(DateTime.GetHour(DateTime.Now),DateTime.GetMinute(DateTime.Now))=True Then
Else
End If