Attribute VB_Name = "ModHeiz1"
Option Explicit


Public Declare Function GetTickCount Lib "kernel32" () As Long



Public Type Schalt_Zeit
Stunden As String
Minuten As String
Sekunden As String
Wochentage As String
End Type


Public Type EinZeitd
Gültig As Boolean
ZeitSingle As Single
End Type

Public Type AusZeitd
Gültig As Boolean
ZeitSingle As Single
End Type

Public Type Wochent
AnzahlEin As Integer
AnzahlAus As Integer
EinZeit(8) As EinZeitd ' 1..6 und ev. ein zusätzliches Ein
AusZeit(8) As AusZeitd ' 1..6 und ev. ein zusätzliches Aus
End Type

Public Type Linie
StartPunkt As Single
EndPunkt As Single
End Type

Public Type GrafikWochentag
LinienNr As Integer
Linie(6) As Linie
End Type
Private Sub Main()
    Load MP_Remote
End Sub
Public Sub Aus()
    Unload MP_Remote
    End
End Sub
Function HextoStr_DateTime(MyString As String) As String
    If Len(MyString) <> 0 Then
        While Len(MyString) <> 0
             HextoStr_DateTime = Hex(Asc(Left(MyString, 1))) & " : "
            MyString = Right(MyString, (Len(MyString) - 1))
        Wend
    Else
        Exit Function
    End If
End Function
Function DoppelteHex10_rausStr(ByVal OriginalStr As String) As String

    ' entferne doppelte "Hex10" in String OriginalStr

Dim Pos As Integer
Dim RestStr As String
    
 ' erst ganze Zeile
 RestStr = OriginalStr
 
 DoppelteHex10_rausStr = ""
 Do
     ' Soll heissen: suche ab Zeichen 1 im string RestStr nach Zeichen Hex10 und gib die Position im String zurück
     Pos = InStr(1, RestStr, Chr$(&H10), vbTextCompare)

     ' kein "Hex10"-Zeichen gefunden oder ist letztes Zeichen
     If Pos = 0 Or Pos = Len(RestStr) Then
         DoppelteHex10_rausStr = DoppelteHex10_rausStr + RestStr
         RestStr = ""
         Pos = 0
     Else
        ' was gefunden-->ersetzen
        
        ' Zuerst das linke Teil bis zu Hex10 nehmen
        DoppelteHex10_rausStr = DoppelteHex10_rausStr + Left(RestStr, Pos)
        ' rechts von Zeichen: der Rest
        RestStr = Right(RestStr, Len(RestStr) - Pos)
        ' wenn jetzt beim Rest auch ein 10H
        If Left(RestStr, 1) = Chr$(&H10) Then
            RestStr = Right(RestStr, Len(RestStr) - 1)
        Else
        End If
     
     End If
 
 Loop Until Pos = 0

End Function

Function VerdoppleHex10Str(ByVal OriginalStr As String) As String

    ' verdoppeln  "Hex10" in String OriginalStr

Dim Pos As Integer
Dim RestStr As String
   
    
    
 ' erst ganze Zeile
 RestStr = OriginalStr
 
 VerdoppleHex10Str = ""
 
 Do
     ' Soll heissen: suche ab Zeichen 1 im string RestStr nach Zeiche Hex 10 und gib die Position im String zurück
     Pos = InStr(1, RestStr, Chr$(&H10), vbTextCompare)

     ' kein "Hex10"-Zeichen gefunden
     If Pos = 0 Then
         VerdoppleHex10Str = VerdoppleHex10Str + RestStr
         RestStr = ""
         Pos = 0
     Else
        ' was gefunden-->noch Hex10 dazu
        
        ' Zuerst das linke Teil bis zu Hex10 nehmen
        VerdoppleHex10Str = VerdoppleHex10Str + Left(RestStr, Pos) + Chr$(&H10)
        ' rechts von Zeichen: der Rest
        RestStr = Right(RestStr, Len(RestStr) - Pos)
        
     End If
 
 Loop Until Pos = 0



End Function

Function isTime(timestr As String) As Boolean
' diese Funktion erwartet den Zeitstring in folgendem Format:
' 00:00:00

isTime = True

' stimmt das Format ????
If Mid(timestr, 3, 1) <> ":" And Mid(timestr, 5, 1) <> ":" Then
    
    isTime = False
' stimmt die Länge des Strings ?
ElseIf Len(timestr) <> 8 Then
    
    isTime = False
' Stunden im richtigen Bereich ?
ElseIf Int(Mid(timestr, 1, 2)) < 0 And Int(Mid(timestr, 1, 2)) > 23 Then

    isTime = False

' Minuten im richtigen Bereich ?
ElseIf Int(Mid(timestr, 4, 2)) < 0 And Int(Mid(timestr, 4, 2)) > 59 Then

    isTime = False

' Sekunden im richtigen Bereich ?
ElseIf Int(Right(timestr, 2)) < 0 And Int(Right(timestr, 2)) > 59 Then

    isTime = False

End If



End Function
Function AscToBCD(ASCII_1_2 As String) As String
Dim Ziffer1, Ziffer2, Summe As Integer


Ziffer1 = Asc(Left(ASCII_1_2, 1)) - 48
Ziffer2 = Asc(Right(ASCII_1_2, 1)) - 48

AscToBCD = Chr$(Ziffer1 * 16 + Ziffer2)


End Function
Function BCDToASCII(BCD As String) As String

If BCD = "" Then
BCDToASCII = "0" 'ist zwar Käse, aber es geht weiter
Else
BCDToASCII = Hex(Asc(BCD))
End If

End Function

Function BytToBOOL(Byt As String) As String
Dim I, Rest As Integer

If Byt = "" Then
    BytToBOOL = "00000000"
Else
Rest = Asc(Byt)
    For I = 1 To 8
        BytToBOOL = Format((Rest Mod 2), "#0") + BytToBOOL
        Rest = Int(Rest / 2)
    Next I
End If
End Function
Function BOOLToByt(BOOL As String) As Integer
Dim Sammel As Integer
Dim Rest As String

Rest = BOOL

Do

    Sammel = Sammel * 2 + Int(Mid(Rest, 1, 1))
    Rest = Right(Rest, Len(Rest) - 1)

Loop Until Len(Rest) = 0

BOOLToByt = Sammel
End Function

Function TimeStrToSingle(Time As String) As Single
'Erwartet wird ein String in folgendem Format: "HH:MM:SS"
Dim StdInt, MinInt, SekInt As Integer

    StdInt = Int(Mid(Time, 1, 2))
    MinInt = Int(Mid(Time, 4, 2))
    SekInt = Int(Mid(Time, 7, 2))
    
TimeStrToSingle = StdInt + (MinInt / 60) + (SekInt / 3600)

End Function
Function StrToLong(Byte1_2 As String) As Long
Dim L, LH, LL As Long

If Byte1_2 = "" Then

    L = 0

Else

    
    LH = Asc(Left(Byte1_2, 1)) * CLng(256)
    LL = Asc(Right(Byte1_2, 1))
    L = LH + LL
    
End If
    
    StrToLong = L


End Function
