Android Code Snippet time switch class

Discussion in 'Code Snippets' started by MarkusR, May 21, 2019.

  1. MarkusR

    MarkusR Well-Known Member Licensed User

    whatitis.jpg

    Class Name TimeSwitch
    Code:
    'time switch

    Sub Class_Globals
      
        
    Type HourSettings(q1 As Boolean,q2 As Boolean,q3 As Boolean,q4 As Boolean)
        
    Private DaySettings(24As 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
    Code:
    If TimeSwitch1.IsOn(DateTime.GetHour(DateTime.Now),DateTime.GetMinute(DateTime.Now))=True Then
    Else
    End If
     
    fredo and Rubsanpe like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice