Attribute VB_Name = "mod_Alert"
Option Explicit

Public Type AgendaRecord
    Mode As Boolean
    Priority As Integer
    Jaar As Long
    Maand As Long
    Dag As Long
    Maandag As Boolean
    Dinsdag As Boolean
    Woensdag As Boolean
    Donderdag As Boolean
    Vrijdag As Boolean
    Zaterdag As Boolean
    Zondag As Boolean
    BeginUur As Long
    BeginMin As Long
    EindUur As Long
    EindMin As Long
    Datum As Date
    Tijd As Date
    About As String
End Type

Public Const conHwndTopmost = -1
Public Const conHwndTopNot = -2
Public Const conSwpNoActivate = &H10
Public Const conSwpShowWindow = &H40
Public Const GW_HWNDFIRST = 0
Public Const GW_HWNDNEXT = 2
Public Const GWL_EXSTYLE = (-20)
Public Const GWL_HWNDPARENT = (-8)
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const WS_BORDER = &H800000
Public Const WS_EX_TOOLWINDOW = &H80
Public Const WS_VISIBLE = &H10000000


Public iniValue As Variant
Public PaddStart As Date
Public PaddEnd As Date
Public strApplication As String
Public strProgram As String
Public strProgramdir As String

Public Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Public Function Activate_Application() As Long
    Dim lngStyle As Long
    Dim Addcounter As Integer
    Dim tempcheck As String
    Dim currWnd As Long
    Dim Length As Long
    Dim listItem$
    Dim IsTask As Long
    Dim Counting As Long
    
    Activate_Application = -1
    IsTask = WS_VISIBLE Or WS_BORDER
    
    currWnd = GetWindow(frmMain.hwnd, GW_HWNDFIRST)
    While currWnd <> 0
        If IsWindowVisible(currWnd) Then
            If GetParent(currWnd) = 0 Then
                lngStyle = GetWindowLong(currWnd, GWL_HWNDPARENT)
                If (lngStyle = 0) Or IsToolWindow(lngStyle) Then
                    If Not IsToolWindow(currWnd) Then
                        Length = GetWindowTextLength(currWnd)
                        listItem$ = Space$(Length + 1)
                        Length = GetWindowText(currWnd, listItem$, Length + 1)
                        If (Left(listItem$, Length) = strApplication) Then
                            Activate_Application = currWnd
                       End If
                    End If
                End If
            End If
        End If
        currWnd = GetWindow(currWnd, GW_HWNDNEXT)
    Wend
End Function

Public Sub Agenda_Convert(strAC As String, Agend As AgendaRecord)
    Dim Datum As Date
    Dim strDatum As String
    Dim lngStart As Long
    Dim lngCur As Long
    
    
    Datum = Now
    If strAC = "" Then
        'Leeg record
        Agend.Mode = False
        Agend.Priority = 0
        Agend.Maandag = False
        Agend.Dinsdag = False
        Agend.Woensdag = False
        Agend.Donderdag = False
        Agend.Vrijdag = False
        Agend.Zaterdag = False
        Agend.Zondag = False
        If Agend.EindUur > 24 Then
            Agend.EindUur = 23
            Agend.EindMin = 59
        End If
        Agend.About = ""
        Agend.Datum = Datum
        Agend.Tijd = DateAdd("h", "1", Datum)
    Else
        lngStart = "1"
        lngCur = InStr(lngStart, strAC, Chr(1))
        strDatum = Mid(strAC, lngStart, lngCur - lngStart)
        If Val(Left(strDatum, 8)) = 0 Then
            Agend.Datum = DateSerial(Year(Datum), Month(Datum), Day(Datum)) + TimeSerial(Val(Mid(strDatum, 9, 2)), Val(Mid(strDatum, 11, 2)), 0)
        Else
            Agend.Datum = DateSerial(Val(Mid(strDatum, 1, 4)), Val(Mid(strDatum, 5, 2)), Val(Mid(strDatum, 7, 2))) + TimeSerial(Val(Mid(strDatum, 9, 2)), Val(Mid(strDatum, 11, 2)), 0)
        End If
        lngStart = lngCur + 1
        lngCur = InStr(lngStart, strAC, Chr(1))
        strDatum = Mid(strAC, lngStart, lngCur - lngStart)
        If Val(Left(strDatum, 8)) = 0 Then
            Agend.Tijd = DateSerial(Year(Datum), Month(Datum), Day(Datum)) + TimeSerial(Val(Mid(strDatum, 9, 2)), Val(Mid(strDatum, 11, 2)), 0)
        Else
            Agend.Tijd = DateSerial(Val(Mid(strDatum, 1, 4)), Val(Mid(strDatum, 5, 2)), Val(Mid(strDatum, 7, 2))) + TimeSerial(Val(Mid(strDatum, 9, 2)), Val(Mid(strDatum, 11, 2)), 0)
        End If
        lngStart = lngCur + 1
        lngCur = InStr(lngStart, strAC, Chr(1))
        Agend.About = Mid(strAC, lngStart, lngCur - lngStart)
        
        lngStart = lngCur + 1
        lngCur = InStr(lngStart, strAC, Chr(1))
        strDatum = Mid(strAC, lngStart, lngCur - lngStart)
        If strDatum = "0" Then
            Agend.Mode = False
        Else
            Agend.Mode = True
        End If
        
        lngStart = lngCur + 1
        lngCur = InStr(lngStart, strAC, Chr(1))
        Agend.Priority = Val(Mid(strAC, lngStart, lngCur - lngStart))
        
        lngStart = lngCur + 1
        lngCur = InStr(lngStart, strAC, Chr(1))
        strDatum = Mid(strAC, lngStart, lngCur - lngStart)
        If strDatum = "0" Then
            Agend.Maandag = False
        Else
            Agend.Maandag = True
        End If
        
        lngStart = lngCur + 1
        lngCur = InStr(lngStart, strAC, Chr(1))
        strDatum = Mid(strAC, lngStart, lngCur - lngStart)
        If strDatum = "0" Then
            Agend.Dinsdag = False
        Else
            Agend.Dinsdag = True
        End If
        
        lngStart = lngCur + 1
        lngCur = InStr(lngStart, strAC, Chr(1))
        strDatum = Mid(strAC, lngStart, lngCur - lngStart)
        If strDatum = "0" Then
            Agend.Woensdag = False
        Else
            Agend.Woensdag = True
        End If
        
        lngStart = lngCur + 1
        lngCur = InStr(lngStart, strAC, Chr(1))
        strDatum = Mid(strAC, lngStart, lngCur - lngStart)
        If strDatum = "0" Then
            Agend.Donderdag = False
        Else
            Agend.Donderdag = True
        End If
    
        lngStart = lngCur + 1
        lngCur = InStr(lngStart, strAC, Chr(1))
        strDatum = Mid(strAC, lngStart, lngCur - lngStart)
        If strDatum = "0" Then
            Agend.Vrijdag = False
        Else
            Agend.Vrijdag = True
        End If
    
        lngStart = lngCur + 1
        lngCur = InStr(lngStart, strAC, Chr(1))
        strDatum = Mid(strAC, lngStart, lngCur - lngStart)
        If strDatum = "0" Then
            Agend.Zaterdag = False
        Else
            Agend.Zaterdag = True
        End If
    
        lngStart = lngCur + 1
        lngCur = InStr(lngStart, strAC, Chr(1))
        strDatum = Mid(strAC, lngStart, lngCur - lngStart)
        If strDatum = "0" Then
            Agend.Zondag = False
        Else
            Agend.Zondag = True
        End If
    
        Agend.Jaar = Year(Agend.Datum)
        Agend.Maand = Month(Agend.Datum)
        Agend.Dag = Day(Agend.Datum)
        Agend.BeginUur = Hour(Agend.Datum)
        Agend.BeginMin = Minute(Agend.Datum)
        Agend.EindMin = Minute(Agend.Tijd)
        Agend.EindUur = Hour(Agend.Tijd)
    
    End If
    PaddStart = Agend.Datum
    PaddEnd = Agend.Tijd
End Sub

Public Sub Agenda_ReloadFull(lstAUS As ListBox, lstAS As ListBox, lstW As ListBox, lstAG As ListBox)
    Dim lngLoop As Long
    Dim booIni As Boolean
    Dim strIni As String
    Dim lngMax As Long
    Dim tmpDatum As Date
    Dim chkDatum As Date
    Dim agTemp As AgendaRecord
    
    'Nu nog even die troep inlaaien
    booIni = INI_GetKey("AGENDA", "ID", strProgramdir & "\padd\agenda.ini")
    lstAUS.Clear
    If booIni Then
        lngMax = iniValue
        For lngLoop = 0 To lngMax - 1
            strIni = CStr(lngLoop + 1)
            booIni = INI_GetKey("AGENDA", strIni, strProgramdir & "\padd\agenda.ini")
            If booIni = True Then
                lstAUS.AddItem Database_Decrypt(iniValue)
                lstAUS.ItemData(lstAUS.NewIndex) = lngLoop
            End If
        Next
    End If
    lstAS.Clear
    lstW.Clear
    For lngLoop = 0 To lstAUS.ListCount - 1
        strIni = lstAUS.List(lngLoop)
        If Left(strIni, 8) = "00000000" Then
            Agenda_Convert lstAUS.List(lngLoop), agTemp
            If agTemp.Zondag = True Then
                lstW.AddItem "1" & Chr(1) & lstAUS.List(lngLoop)
                lstW.ItemData(lstW.NewIndex) = lstAUS.ItemData(lngLoop)
            End If
            If agTemp.Maandag = True Then
                lstW.AddItem "2" & Chr(1) & lstAUS.List(lngLoop)
                lstW.ItemData(lstW.NewIndex) = lstAUS.ItemData(lngLoop)
            End If
            If agTemp.Dinsdag = True Then
                lstW.AddItem "3" & Chr(1) & lstAUS.List(lngLoop)
                lstW.ItemData(lstW.NewIndex) = lstAUS.ItemData(lngLoop)
            End If
            If agTemp.Woensdag = True Then
                lstW.AddItem "4" & Chr(1) & lstAUS.List(lngLoop)
                lstW.ItemData(lstW.NewIndex) = lstAUS.ItemData(lngLoop)
            End If
            If agTemp.Donderdag = True Then
                lstW.AddItem "5" & Chr(1) & lstAUS.List(lngLoop)
                lstW.ItemData(lstW.NewIndex) = lstAUS.ItemData(lngLoop)
            End If
            If agTemp.Vrijdag = True Then
                lstW.AddItem "6" & Chr(1) & lstAUS.List(lngLoop)
                lstW.ItemData(lstW.NewIndex) = lstAUS.ItemData(lngLoop)
            End If
            If agTemp.Zaterdag = True Then
                lstW.AddItem "7" & Chr(1) & lstAUS.List(lngLoop)
                lstW.ItemData(lstW.NewIndex) = lstAUS.ItemData(lngLoop)
            End If
        Else
            If Val(Mid(strIni, 1, 8)) >= Val(Format(Now, "YYYYMMDD")) And Val(Mid(strIni, 1, 8)) <= Val(Format(DateAdd("ww", "1", Now), "YYYYMMDD")) Then
                lstAS.AddItem lstAUS.List(lngLoop)
                lstAS.ItemData(lstAS.NewIndex) = lstAUS.ItemData(lngLoop)
            End If
        End If
    Next
    tmpDatum = Now
    lngMax = Weekday(Now)
    For lngLoop = 0 To lstW.ListCount - 1
        strIni = lstW.List(lngLoop)
        Select Case lngMax
            Case 1      'Zondag
                Select Case Left(lstW.List(lngLoop), 1)
                    Case 1      'zondag
                        lstAS.AddItem Format(DateAdd("d", 0, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 0, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 2      'maandag
                        lstAS.AddItem Format(DateAdd("d", 1, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 1, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 3      'dinsdag
                        lstAS.AddItem Format(DateAdd("d", 2, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 2, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 4      'woensdag
                        lstAS.AddItem Format(DateAdd("d", 3, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 3, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 5      'donderdag
                        lstAS.AddItem Format(DateAdd("d", 4, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 4, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 6      'vrijdag
                        lstAS.AddItem Format(DateAdd("d", 5, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 5, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 7      'zaterdag
                        lstAS.AddItem Format(DateAdd("d", 6, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 6, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                End Select
            Case 2      'maandag
                Select Case Left(lstW.List(lngLoop), 1)
                    Case 1      'zondag
                        lstAS.AddItem Format(DateAdd("d", 6, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 1, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 2      'maandag
                        lstAS.AddItem Format(DateAdd("d", 0, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 2, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 3      'dinsdag
                        lstAS.AddItem Format(DateAdd("d", 1, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 3, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 4      'woensdag
                        lstAS.AddItem Format(DateAdd("d", 2, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 4, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 5      'donderdag
                        lstAS.AddItem Format(DateAdd("d", 3, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 5, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 6      'vrijdag
                        lstAS.AddItem Format(DateAdd("d", 4, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 6, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 7      'zaterdag
                        lstAS.AddItem Format(DateAdd("d", 5, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 0, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                End Select
            Case 3      'dinsdag
                Select Case Left(lstW.List(lngLoop), 1)
                    Case 1      'zondag
                        lstAS.AddItem Format(DateAdd("d", 5, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 1, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 2      'maandag
                        lstAS.AddItem Format(DateAdd("d", 6, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 2, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 3      'dinsdag
                        lstAS.AddItem Format(DateAdd("d", 0, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 3, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 4      'woensdag
                        lstAS.AddItem Format(DateAdd("d", 1, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 4, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 5      'donderdag
                        lstAS.AddItem Format(DateAdd("d", 2, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 5, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 6      'vrijdag
                        lstAS.AddItem Format(DateAdd("d", 3, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 6, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 7      'zaterdag
                        lstAS.AddItem Format(DateAdd("d", 4, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 0, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                End Select
            Case 4      'woensdag
                Select Case Left(lstW.List(lngLoop), 1)
                    Case 1      'zondag
                        lstAS.AddItem Format(DateAdd("d", 4, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 1, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 2      'maandag
                        lstAS.AddItem Format(DateAdd("d", 5, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 2, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 3      'dinsdag
                        lstAS.AddItem Format(DateAdd("d", 6, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 3, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 4      'woensdag
                        lstAS.AddItem Format(DateAdd("d", 0, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 4, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 5      'donderdag
                        lstAS.AddItem Format(DateAdd("d", 1, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 5, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 6      'vrijdag
                        lstAS.AddItem Format(DateAdd("d", 2, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 6, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 7      'zaterdag
                        lstAS.AddItem Format(DateAdd("d", 3, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 0, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                End Select
            Case 5      'donderdag
                Select Case Left(lstW.List(lngLoop), 1)
                    Case 1      'zondag
                        lstAS.AddItem Format(DateAdd("d", 3, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 1, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 2      'maandag
                        lstAS.AddItem Format(DateAdd("d", 4, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 2, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 3      'dinsdag
                        lstAS.AddItem Format(DateAdd("d", 5, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 3, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 4      'woensdag
                        lstAS.AddItem Format(DateAdd("d", 6, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 4, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 5      'donderdag
                        lstAS.AddItem Format(DateAdd("d", 0, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 5, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 6      'vrijdag
                        lstAS.AddItem Format(DateAdd("d", 1, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 6, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 7      'zaterdag
                        lstAS.AddItem Format(DateAdd("d", 2, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 0, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                End Select
            Case 6      'vrijdag
                Select Case Left(lstW.List(lngLoop), 1)
                    Case 1      'zondag
                        lstAS.AddItem Format(DateAdd("d", 2, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 1, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 2      'maandag
                        lstAS.AddItem Format(DateAdd("d", 3, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 2, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 3      'dinsdag
                        lstAS.AddItem Format(DateAdd("d", 4, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 3, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 4      'woensdag
                        lstAS.AddItem Format(DateAdd("d", 5, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 4, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 5      'donderdag
                        lstAS.AddItem Format(DateAdd("d", 6, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 5, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 6      'vrijdag
                        lstAS.AddItem Format(DateAdd("d", 0, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 6, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 7      'zaterdag
                        lstAS.AddItem Format(DateAdd("d", 1, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 0, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                End Select
            Case 7      'Zaterdag
                Select Case Left(lstW.List(lngLoop), 1)
                    Case 1      'zondag
                        lstAS.AddItem Format(DateAdd("d", 1, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 1, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 2      'maandag
                        lstAS.AddItem Format(DateAdd("d", 2, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 2, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 3      'dinsdag
                        lstAS.AddItem Format(DateAdd("d", 3, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 3, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 4      'woensdag
                        lstAS.AddItem Format(DateAdd("d", 4, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 4, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 5      'donderdag
                        lstAS.AddItem Format(DateAdd("d", 5, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 5, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 6      'vrijdag
                        lstAS.AddItem Format(DateAdd("d", 6, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 6, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                    Case 7      'zaterdag
                        lstAS.AddItem Format(DateAdd("d", 0, tmpDatum), "YYYYMMDD") & Mid(strIni, 11, 4) & Chr(1) & Format(DateAdd("d", 0, tmpDatum), "YYYYMMDD") & Mid(strIni, 24)
                        lstAS.ItemData(lstAS.NewIndex) = lstW.ItemData(lngLoop)
                End Select
        End Select
    Next
    lstAG.Clear
    For lngLoop = 0 To lstAS.ListCount - 1
        Agenda_Convert lstAS.List(lngLoop), agTemp
        If Format(chkDatum, "YYYYMMDD") <> Format(agTemp.Datum, "YYYYMMDD") Then
            'lstAG.AddItem Format(agTemp.Datum, "YYYYMM.DD dddd")
            'lstAG.ItemData(lstAG.NewIndex) = -1
        End If
        chkDatum = agTemp.Datum
        lstAG.AddItem lstAS.List(lngLoop)
        lstAG.ItemData(lstAG.NewIndex) = lstAS.ItemData(lngLoop)
    Next
End Sub

Public Function Database_Decrypt(strIn) As String
    Dim strOut As String
    Dim lngLoop As Long
    
    strOut = ""
    For lngLoop = 1 To Len(strIn) Step 3
        strOut = strOut & Chr(Val(Mid(strIn, lngLoop, 3)))
    Next
    Database_Decrypt = strOut
End Function

Public Function Database_Encrypt(strIn) As String
    Dim strOut As String
    Dim lngLoop As Long
    
    strOut = ""
    For lngLoop = 0 To Len(strIn) - 1
        strOut = strOut & Format(Asc(Mid(strIn, lngLoop + 1, 1)), "000")
    Next
    Database_Encrypt = strOut
End Function

Public Function INI_GetKey(SectionName As String, KeyName As String, IniFileName As String) As Boolean
    Dim ReturnString As String
    Dim ReturnValue As Long
    
    On Local Error GoTo GetKey_Err
    ReturnString = String$(32000, 0)
    iniValue = ""
    ReturnValue = GetPrivateProfileString(SectionName & Chr(0), KeyName, "NotFound", ReturnString, Len(ReturnString), IniFileName & Chr(0))
    If Left(ReturnString, InStr(ReturnString, Chr$(0)) - 1) = "NotFound" Then
        INI_GetKey = False
    Else
        INI_GetKey = True
        iniValue = Left(ReturnString, InStr(ReturnString, Chr$(0)) - 1)
    End If

GetKey_End:
    Exit Function

GetKey_Err:
    MsgBox "Error Retrieving Key"
    INI_GetKey = False
    Resume GetKey_End
End Function

Public Function IsToolWindow(ByVal hwnd As Long) As Boolean
   ' Check for toolwindow style bit.
   IsToolWindow = ((GetWindowLong(hwnd, GWL_EXSTYLE) And WS_EX_TOOLWINDOW) = WS_EX_TOOLWINDOW)
End Function

