Attribute VB_Name = "mod_Padd"
Option Explicit

Public intMaand As Integer
Public strLoadClick As String
Public strOverviewClick As String
Public intUndo As Integer
Public strField As String

Public PaddStart As Date
Public PaddEnd As Date
Public PaddMode As Integer
Public PaddPrio As Long

Private Const MaxPath = 260

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 Type BookRecord
    ID As String
    Achternaam As String
    Voorletters As String
    Displaynaam As String
    Adres1 As String
    Adres2 As String
    Postcode As String
    Plaats As String
    Provincie As String
    Land As String
    Telefoon As String
    Fax As String
    Mobiel As String
    Telwerk As String
    FaxWerk As String
    Email As String
    URL As String
    Notities As String
    MailList As String
End Type

Public bookRec As BookRecord
Public text_overviewA As String
Public text_overviewB As String
Public text_overviewC As String

Public Type SYSTEMTIME ' 16 Bytes
    wYear As Integer
    wMonth As Integer
    wDayOfWeek As Integer
    wDay As Integer
    wHour As Integer
    wMinute As Integer
    wSecond As Integer
    wMilliseconds As Integer
End Type

Public Type TIME_ZONE_INFORMATION
    Bias As Long
    StandardName(31) As Integer
    StandardDate As SYSTEMTIME
    StandardBias As Long
    DaylightName(31) As Integer
    DaylightDate As SYSTEMTIME
    DaylightBias As Long
End Type

Public Declare Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
Public Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

Public Sub Address_DeleteFile()
    If (MsgBox("Are you sure to delete this item?", vbYesNo, "LCARS Terminal") = vbYes) Then
        Kill strProgramdir & "\padd\addressbook\" & bookRec.ID
        Address_Init
        Address_Load -1
        intUndo = -1
    End If
End Sub

Public Sub Address_ImportExport(AIEmode As Integer)
    Dim lngFields(1 To 17) As Long
    Dim AIEbookrec As BookRecord
    Dim lngLoop As Long
    Dim AIEstring As String
    Dim tmpString As String
    Dim tmpChar As String
    Dim fptr
    Dim Counter As Long
    Dim strFilename As String
    Dim strRequester As String
    Dim lngCount As Long
    Dim lngChars As Long
    Dim booQuote As Boolean
    Dim lngWord As Long
    
    '0=import, 1=export
    
    
    If Check_Shareware = "" Then
        MsgBox RegisterText, vbInformation, "LCARS Terminal"
    End If
    
    'First Name,Last Name,Middle Name,Name,Nickname,E-mail Address,Home Street,Home City,Home Postal Code,Home State,Home Country/Region,Home Phone,Home Fax,Mobile Phone,Personal Web Page,Business Street,Business City,Business Postal Code,Business State,Business Country/Region,Business Web Page,Business Phone,Business Fax,Pager,Company,Job Title,Department,Office Location,Notes
    If AIEmode = 1 Then
        INI_GetKey "ADDRESS", "textexport", strProgramdir & strThemedir & strThemeName & ".skn"
        strRequester = iniValue
        strFilename = InputBox(strRequester, "LCARS Terminal", "C:\lcars-addressbook.csv")
        If strFilename <> "" Then
            On Error GoTo writeerror
            fptr = freefile
            Open strFilename For Output As #fptr
            INI_GetKey "ADDRESS", "exportstring", strProgramdir & strThemedir & strThemeName & ".skn"
            strRequester = iniValue
            Print #fptr, strRequester
            'Exporteren die hap.
            For lngLoop = 0 To frmMain.lstSorted1.ListCount - 1
                If frmMain.lstSorted1.List(lngLoop) <> "" Then
                    Address_LoadFile Mid(frmMain.lstSorted1.List(lngLoop), InStr(frmMain.lstSorted1.List(lngLoop), Chr(1)) + 1), AIEbookrec
                    AIEstring = ""

                    If InStr(AIEbookrec.Displaynaam, ";") Then
                        AIEstring = AIEstring & Chr(34) & AIEbookrec.Displaynaam & Chr(34)
                    Else
                        AIEstring = AIEstring & AIEbookrec.Displaynaam
                    End If
                    AIEstring = AIEstring & ";"

                    If InStr(AIEbookrec.Achternaam, ";") Then
                        AIEstring = AIEstring & Chr(34) & AIEbookrec.Achternaam & Chr(34)
                    Else
                        AIEstring = AIEstring & AIEbookrec.Achternaam
                    End If
                    AIEstring = AIEstring & ";"
                    
                    If InStr(AIEbookrec.Voorletters, ";") Then
                        AIEstring = AIEstring & Chr(34) & AIEbookrec.Voorletters & Chr(34)
                    Else
                        AIEstring = AIEstring & AIEbookrec.Voorletters
                    End If
                    AIEstring = AIEstring & ";"
                    
                    If InStr(AIEbookrec.Adres1, ";") Then
                        AIEstring = AIEstring & Chr(34) & AIEbookrec.Adres1 & Chr(34)
                    Else
                        AIEstring = AIEstring & AIEbookrec.Adres1
                    End If
                    AIEstring = AIEstring & ";"
                    
                    If InStr(AIEbookrec.Adres2, ";") Then
                        AIEstring = AIEstring & Chr(34) & AIEbookrec.Adres2 & Chr(34)
                    Else
                        AIEstring = AIEstring & AIEbookrec.Adres2
                    End If
                    AIEstring = AIEstring & ";"
                    
                    If InStr(AIEbookrec.Postcode, ";") Then
                        AIEstring = AIEstring & Chr(34) & AIEbookrec.Postcode & Chr(34)
                    Else
                        AIEstring = AIEstring & AIEbookrec.Postcode
                    End If
                    AIEstring = AIEstring & ";"
            
                    If InStr(AIEbookrec.Plaats, ";") Then
                        AIEstring = AIEstring & Chr(34) & AIEbookrec.Plaats & Chr(34)
                    Else
                        AIEstring = AIEstring & AIEbookrec.Plaats
                    End If
                    AIEstring = AIEstring & ";"
            
                    If InStr(AIEbookrec.Provincie, ";") Then
                        AIEstring = AIEstring & Chr(34) & AIEbookrec.Provincie & Chr(34)
                    Else
                        AIEstring = AIEstring & AIEbookrec.Provincie
                    End If
                    AIEstring = AIEstring & ";"
            
                    If InStr(AIEbookrec.Land, ";") Then
                        AIEstring = AIEstring & Chr(34) & AIEbookrec.Land & Chr(34)
                    Else
                        AIEstring = AIEstring & AIEbookrec.Land
                    End If
                    AIEstring = AIEstring & ";"
            
                    If InStr(AIEbookrec.Telefoon, ";") Then
                        AIEstring = AIEstring & Chr(34) & AIEbookrec.Telefoon & Chr(34)
                    Else
                        AIEstring = AIEstring & AIEbookrec.Telefoon
                    End If
                    AIEstring = AIEstring & ";"
            
                    If InStr(AIEbookrec.Fax, ";") Then
                        AIEstring = AIEstring & Chr(34) & AIEbookrec.Fax & Chr(34)
                    Else
                        AIEstring = AIEstring & AIEbookrec.Fax
                    End If
                    AIEstring = AIEstring & ";"
            
                    If InStr(AIEbookrec.Mobiel, ";") Then
                        AIEstring = AIEstring & Chr(34) & AIEbookrec.Mobiel & Chr(34)
                    Else
                        AIEstring = AIEstring & AIEbookrec.Mobiel
                    End If
                    AIEstring = AIEstring & ";"
            
                    If InStr(AIEbookrec.Email, ";") Then
                        AIEstring = AIEstring & Chr(34) & AIEbookrec.Email & Chr(34)
                    Else
                        AIEstring = AIEstring & AIEbookrec.Email
                    End If
                    AIEstring = AIEstring & ";"
                    
                    If InStr(AIEbookrec.URL, ";") Then
                        AIEstring = AIEstring & Chr(34) & AIEbookrec.URL & Chr(34)
                    Else
                        AIEstring = AIEstring & AIEbookrec.URL
                    End If
                    AIEstring = AIEstring & ";"
                    
                    If InStr(AIEbookrec.Telwerk, ";") Then
                        AIEstring = AIEstring & Chr(34) & AIEbookrec.Telwerk & Chr(34)
                    Else
                        AIEstring = AIEstring & AIEbookrec.Telwerk
                    End If
                    AIEstring = AIEstring & ";"
        
                    If InStr(AIEbookrec.FaxWerk, ";") Then
                        AIEstring = AIEstring & Chr(34) & AIEbookrec.FaxWerk & Chr(34)
                    Else
                        AIEstring = AIEstring & AIEbookrec.FaxWerk
                    End If
                    AIEstring = AIEstring & ";"
        
                    tmpString = ""
                    For Counter = 1 To Len(AIEbookrec.Notities)
                        tmpChar = Mid(AIEbookrec.Notities, Counter, 1)
                        If Asc(tmpChar) = 13 Then
                            tmpString = tmpString & " "
                        ElseIf Asc(tmpChar) <> 10 Then
                            tmpString = tmpString & tmpChar
                        End If
                    Next
                    If InStr(tmpString, ";") Then
                        AIEstring = AIEstring & Chr(34) & tmpString & Chr(34)
                    Else
                        AIEstring = AIEstring & tmpString
                    End If
                    AIEstring = AIEstring
                    
                    Print #fptr, AIEstring
                End If
            Next
            Close #fptr
        End If
    Else
        'Import file
        INI_GetKey "ADDRESS", "textimport", strProgramdir & strThemedir & strThemeName & ".skn"
        strRequester = iniValue
        strFilename = InputBox(strRequester, "LCARS Terminal", "C:\lcars-addressbook.csv")
        If strFilename <> "" Then
            On Error GoTo writeerror
            fptr = freefile
            Open strFilename For Input As #fptr
            Line Input #fptr, tmpString
            'strField hhehehhe.
            'Even kijken wat er kan, want het kan ook dat er een , of ; gebruikt wordt!
            If InStr(tmpString, ";") > 0 Then
                strField = ";"
            Else
                strField = ","
            End If
            
            inputBack = tmpString
            frmMain.lstUnsorted.Clear
            Do While Not EOF(fptr)
                Line Input #fptr, tmpString
                If Trim(tmpString) <> "" Then
                    frmMain.lstUnsorted.AddItem tmpString
                End If
            Loop
            Close #fptr
            frmImport.Show 1
            If inputBack <> "" Then
                lngWord = 1
                For Counter = 1 To 17
                    lngChars = InStr(lngWord, inputBack, "=") + 1
                    lngWord = InStr(lngChars, inputBack, ";")
                    lngFields(Counter) = val(Mid(inputBack, lngChars, lngWord - lngChars))
                Next
                For Counter = 0 To frmMain.lstUnsorted.ListCount - 1
                    booQuote = False
                    tmpString = ""
                    lngWord = 1
                    AIEbookrec.Achternaam = ""
                    AIEbookrec.Adres1 = ""
                    AIEbookrec.Adres2 = ""
                    AIEbookrec.Displaynaam = ""
                    AIEbookrec.Email = ""
                    AIEbookrec.Fax = ""
                    AIEbookrec.FaxWerk = ""
                    AIEbookrec.ID = ""
                    AIEbookrec.Land = ""
                    AIEbookrec.MailList = ""
                    AIEbookrec.Mobiel = ""
                    AIEbookrec.Notities = ""
                    AIEbookrec.Plaats = ""
                    AIEbookrec.Postcode = ""
                    AIEbookrec.Provincie = ""
                    AIEbookrec.Telefoon = ""
                    AIEbookrec.Telwerk = ""
                    AIEbookrec.URL = ""
                    AIEbookrec.Voorletters = ""
                    
                    'First Name,Last Name,Middle Name,Name,Nickname,E-mail Address,Home Street,Home City,Home Postal Code,Home State,Home Country/Region,Home Phone,Home Fax,Mobile Phone,Personal Web Page,Business Street,Business City,Business Postal Code,Business State,Business Country/Region,Business Web Page,Business Phone,Business Fax,Pager,Company,Job Title,Department,Office Location,Notes
                    For lngChars = 1 To Len(frmMain.lstUnsorted.List(Counter))
                        tmpChar = Mid(frmMain.lstUnsorted.List(Counter), lngChars, 1)
                        If tmpChar = Chr(34) Then 'Gaat om een "
                            If booQuote = False Then booQuote = True Else booQuote = False
                        End If
                        If tmpChar = strField And booQuote = False Then
                            'Jahoor, scheidingsteken gevonden
                            If Left(tmpString, 1) = Chr(34) And Right(tmpString, 1) = Chr(34) Then
                                tmpString = Mid(tmpString, 2, Len(tmpString) - 2)
                            End If
                            If lngFields(1) = lngWord Then AIEbookrec.Displaynaam = tmpString
                            If lngFields(2) = lngWord Then AIEbookrec.Achternaam = tmpString
                            If lngFields(3) = lngWord Then AIEbookrec.Voorletters = tmpString
                            If lngFields(4) = lngWord Then AIEbookrec.Adres1 = tmpString
                            If lngFields(5) = lngWord Then AIEbookrec.Adres2 = tmpString
                            If lngFields(6) = lngWord Then AIEbookrec.Postcode = tmpString
                            If lngFields(7) = lngWord Then AIEbookrec.Plaats = tmpString
                            If lngFields(8) = lngWord Then AIEbookrec.Provincie = tmpString
                            If lngFields(9) = lngWord Then AIEbookrec.Land = tmpString
                            If lngFields(10) = lngWord Then AIEbookrec.Telefoon = tmpString
                            If lngFields(11) = lngWord Then AIEbookrec.Fax = tmpString
                            If lngFields(12) = lngWord Then AIEbookrec.Mobiel = tmpString
                            If lngFields(13) = lngWord Then AIEbookrec.Email = tmpString
                            If lngFields(14) = lngWord Then AIEbookrec.URL = tmpString
                            If lngFields(15) = lngWord Then AIEbookrec.Telwerk = tmpString
                            If lngFields(16) = lngWord Then AIEbookrec.FaxWerk = tmpString
                            If lngFields(17) = lngWord Then AIEbookrec.Notities = tmpString
                            lngWord = lngWord + 1
                            tmpString = ""
                        Else
                            tmpString = tmpString & tmpChar
                        End If
                    Next
                    lngCount = 0
                    frmMain.File1.Path = strProgramdir & "\padd\addressbook"
                    frmMain.File1.Refresh
                    For lngLoop = 0 To frmMain.File1.ListCount - 1
                        If (val(frmMain.File1.List(lngLoop)) >= lngCount) Then
                            lngCount = val(frmMain.File1.List(lngLoop)) + 1
                        End If
                    Next
                    AIEbookrec.ID = CStr(lngCount) & ".dat"
                    If AIEbookrec.ID <> "-1.dat" And ( _
                        AIEbookrec.Displaynaam <> "" Or _
                        AIEbookrec.Achternaam <> "" Or _
                        AIEbookrec.Voorletters <> "" Or _
                        AIEbookrec.Adres1 <> "" Or _
                        AIEbookrec.Adres2 <> "" Or _
                        AIEbookrec.Postcode <> "" Or _
                        AIEbookrec.Plaats <> "" Or _
                        AIEbookrec.Provincie <> "" Or _
                        AIEbookrec.Land <> "" Or _
                        AIEbookrec.Telefoon <> "" Or _
                        AIEbookrec.Fax <> "" Or _
                        AIEbookrec.Mobiel <> "" Or _
                        AIEbookrec.Telwerk <> "" Or _
                        AIEbookrec.FaxWerk <> "" Or _
                        AIEbookrec.Email <> "" Or _
                        AIEbookrec.URL <> "" Or _
                        AIEbookrec.Notities <> "") _
                    Then
                        fptr = freefile
                        Open strProgramdir & "\padd\addressbook\" & AIEbookrec.ID For Output As #fptr
                        Print #fptr, AIEbookrec.Displaynaam
                        Print #fptr, AIEbookrec.Achternaam
                        Print #fptr, AIEbookrec.Voorletters
                        Print #fptr, AIEbookrec.Adres1
                        Print #fptr, AIEbookrec.Adres2
                        Print #fptr, AIEbookrec.Postcode
                        Print #fptr, AIEbookrec.Plaats
                        Print #fptr, AIEbookrec.Provincie
                        Print #fptr, AIEbookrec.Land
                        Print #fptr, AIEbookrec.Telefoon
                        Print #fptr, AIEbookrec.Fax
                        Print #fptr, AIEbookrec.Mobiel
                        Print #fptr, AIEbookrec.Telwerk
                        Print #fptr, AIEbookrec.FaxWerk
                        Print #fptr, AIEbookrec.Email
                        Print #fptr, AIEbookrec.URL
                        Print #fptr, Database_Encrypt(AIEbookrec.Notities)
                        Close #fptr
                    End If
                Next
            End If
        End If
        Address_Init
        Address_Load -1
        intUndo = -1
    End If
    Exit Sub
writeerror:
        INI_GetKey "ADDRESS", "textfileerror", strProgramdir & strThemedir & strThemeName & ".skn"
        strRequester = iniValue
        MsgBox strRequester, vbExclamation, "LCARS Terminal"
    Exit Sub
End Sub

Public Sub Address_Init()
    Dim lngLoop As Long
    Dim booIni As Boolean
    Dim strIni As String
    Dim lngMax As Long
    Dim bookRec As BookRecord
    Dim strTemp As String
    Dim strTitel As String
    Dim fptr
    
    frmMain.lstSorted1.Clear
    frmMain.File1.Path = strProgramdir & "\padd\addressbook"
    frmMain.File1.Refresh
    
    For lngLoop = 0 To frmMain.File1.ListCount - 1
        fptr = freefile
        strTitel = frmMain.File1.List(lngLoop)
        Open strProgramdir & "\padd\addressbook\" & strTitel For Input As #fptr
        Line Input #fptr, strTemp
        frmMain.lstSorted1.AddItem strTemp & Chr(1) & strTitel
        frmMain.lstSorted1.ItemData(frmMain.lstSorted1.NewIndex) = lngLoop
        Close #fptr
    Next
    
    frmMain.lstBox(2).Clear
    For lngLoop = 0 To frmMain.lstSorted1.ListCount - 1
        strIni = frmMain.lstSorted1.List(lngLoop)
        strTemp = Mid(strIni, 1, InStr(strIni, Chr(1)) - 1)
        'address_convert strTemp, bookRec
        frmMain.lstBox(2).AddItem strTemp
        frmMain.lstBox(2).ItemData(frmMain.lstBox(2).NewIndex) = lngLoop
    Next
End Sub

Public Sub Address_Load(intIndex As Integer)
    Dim strIni As String
    Dim lngLoop As Long
    
    If frmMain.lstSorted1.List(intIndex) <> "" Then
        Address_LoadFile Mid(frmMain.lstSorted1.List(intIndex), InStr(frmMain.lstSorted1.List(intIndex), Chr(1)) + 1), bookRec
        frmMain.txtBox(1).Text = bookRec.Displaynaam
        frmMain.txtBox(2).Text = bookRec.Achternaam
        frmMain.txtBox(3).Text = bookRec.Voorletters
        frmMain.txtBox(4).Text = bookRec.Adres1
        frmMain.txtBox(5).Text = bookRec.Adres2
        frmMain.txtBox(6).Text = bookRec.Postcode
        frmMain.txtBox(7).Text = bookRec.Plaats
        frmMain.txtBox(8).Text = bookRec.Provincie
        frmMain.txtBox(9).Text = bookRec.Land
        frmMain.txtBox(10).Text = bookRec.Telefoon
        frmMain.txtBox(11).Text = bookRec.Fax
        frmMain.txtBox(12).Text = bookRec.Mobiel
        frmMain.txtBox(13).Text = bookRec.Email
        frmMain.txtBox(14).Text = bookRec.URL
        frmMain.txtBox(15).Text = bookRec.Telwerk
        frmMain.txtBox(16).Text = bookRec.FaxWerk
        frmMain.txtMBox(1).Text = bookRec.Notities
    Else
        bookRec.ID = ""
        For lngLoop = 0 To 15
            frmMain.txtBox(lngLoop).Text = ""
        Next
        frmMain.txtMBox(1).Text = ""
    End If
End Sub

Public Sub Address_LoadFile(strFile As String, bookRec As BookRecord)
    Dim fptr
    Dim strTemp As String

    fptr = freefile
    Open strProgramdir & "\padd\addressbook\" & strFile For Input As #fptr
    Line Input #fptr, bookRec.Displaynaam
    Line Input #fptr, bookRec.Achternaam
    Line Input #fptr, bookRec.Voorletters
    Line Input #fptr, bookRec.Adres1
    Line Input #fptr, bookRec.Adres2
    Line Input #fptr, bookRec.Postcode
    Line Input #fptr, bookRec.Plaats
    Line Input #fptr, bookRec.Provincie
    Line Input #fptr, bookRec.Land
    Line Input #fptr, bookRec.Telefoon
    Line Input #fptr, bookRec.Fax
    Line Input #fptr, bookRec.Mobiel
    Line Input #fptr, bookRec.Telwerk
    Line Input #fptr, bookRec.FaxWerk
    Line Input #fptr, bookRec.Email
    Line Input #fptr, bookRec.URL
    Line Input #fptr, strTemp
    bookRec.Notities = Database_Decrypt(strTemp)
    bookRec.ID = strFile
    Close #fptr

End Sub

Public Sub Address_SaveFile()
    Dim lngLoop As Long
    Dim lngCount As Long
    Dim fptr
    
    If Check_Shareware = "" Then
        MsgBox RegisterText, vbInformation, "LCARS Terminal"
    End If
    
    lngCount = 0
    If (bookRec.ID = "") Then
        frmMain.File1.Path = strProgramdir & "\padd\addressbook"
        frmMain.File1.Refresh
        For lngLoop = 0 To frmMain.File1.ListCount - 1
            If (val(frmMain.File1.List(lngLoop)) >= lngCount) Then
                lngCount = val(frmMain.File1.List(lngLoop)) + 1
            End If
        Next
        bookRec.ID = CStr(lngCount) & ".dat"
    End If
    If bookRec.ID <> "-1.dat" Then
        fptr = freefile
        Open strProgramdir & "\padd\addressbook\" & bookRec.ID For Output As #fptr
        Print #fptr, frmMain.txtBox(1).Text
        Print #fptr, frmMain.txtBox(2).Text
        Print #fptr, frmMain.txtBox(3).Text
        Print #fptr, frmMain.txtBox(4).Text
        Print #fptr, frmMain.txtBox(5).Text
        Print #fptr, frmMain.txtBox(6).Text
        Print #fptr, frmMain.txtBox(7).Text
        Print #fptr, frmMain.txtBox(8).Text
        Print #fptr, frmMain.txtBox(9).Text
        Print #fptr, frmMain.txtBox(10).Text
        Print #fptr, frmMain.txtBox(11).Text
        Print #fptr, frmMain.txtBox(12).Text
        Print #fptr, frmMain.txtBox(15).Text
        Print #fptr, frmMain.txtBox(16).Text
        Print #fptr, frmMain.txtBox(13).Text
        Print #fptr, frmMain.txtBox(14).Text
        Print #fptr, Database_Encrypt(frmMain.txtMBox(1).Text)
        Close #fptr
    End If
End Sub

Public Sub Agenda_CheckMode()
    Dim lngLoop As Long
    On Error Resume Next
    
    If frmMain.optMode(0).Value = True Then
        For lngLoop = 0 To 6
            frmMain.chkPadd(lngLoop).Enabled = False
        Next
        frmMain.imgBut(AgendaButA).Enabled = True
        frmMain.imgBut(AgendaButB).Enabled = True
        frmMain.imgBut(AgendaButC).Enabled = True
        frmMain.imgBut(AgendaButD).Enabled = True
        frmMain.imgBut(AgendaButE).Enabled = True
        frmMain.imgBut(AgendaButF).Enabled = True
    Else
        For lngLoop = 0 To 6
            frmMain.chkPadd(lngLoop).Enabled = True
        Next
        frmMain.imgBut(AgendaButA).Enabled = False
        frmMain.imgBut(AgendaButB).Enabled = False
        frmMain.imgBut(AgendaButC).Enabled = False
        frmMain.imgBut(AgendaButD).Enabled = False
        frmMain.imgBut(AgendaButE).Enabled = False
        frmMain.imgBut(AgendaButF).Enabled = False
    End If
End Sub

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_Delete()
    Dim lngLoop As Long
    Dim strIni As String
    Dim strTemp As String
    Dim lngCounter As Long
    
    If intUndo >= 0 Then
        If (MsgBox("Are you sure to delete this item?", vbYesNo, "LCARS Terminal") = vbYes) Then
            frmMain.lstAgUnSort.RemoveItem intUndo
            lngCounter = 0
            For lngLoop = 0 To frmMain.lstAgUnSort.ListCount - 1
                lngCounter = lngCounter + 1
                INI_WriteKey "AGENDA", CStr(lngCounter), Database_Encrypt(frmMain.lstAgUnSort.List(lngLoop)), strProgramdir & "\padd\agenda.ini"
            Next
            INI_WriteKey "AGENDA", "ID", CStr(lngCounter), strProgramdir & "\padd\agenda.ini"
    
            Agenda_ReloadFull frmMain.lstAgUnSort, frmMain.lstAgSorted, frmMain.lstWeekly, frmMain.lstAgenda
            Agenda_Init
            Overview_Load 'frmMain.MList1
        End If
    End If
End Sub

Public Sub Agenda_Init()
    Dim lngLoop As Long
    Dim booIni As Boolean
    Dim strIni As String
    Dim lngMax As Long
    Dim strTemp As String
    Dim agTemp As AgendaRecord
    Dim chkDatum As Date
    Dim strCheck As String
    Dim strAbout As String

    frmMain.lstSorted1.Clear
    frmMain.lstBox(2).Clear
    'booIni = INI_GetKey("AGENDA", "ID", strProgramdir & "padd/agenda.ini")
    'If booIni Then
    '    lngMax = iniValue
    '    For lngloop = 0 To lngMax - 1
    '        strIni = CStr(lngloop + 1)
    '        booIni = INI_GetKey("AGENDA", strIni, strProgramdir & "padd/agenda.ini")
    '        strTemp = Database_Decrypt(iniValue)
    '        If booIni = True And Left(strTemp, 8) <> "00000000" Then
    '            frmMain.lstSorted1.AddItem strTemp
    '        End If
    '     Next
    'End If
    For lngLoop = 0 To frmMain.lstAgUnSort.ListCount - 1
        If val(Left(frmMain.lstAgUnSort.List(lngLoop), 8)) > 0 Then
            frmMain.lstSorted1.AddItem frmMain.lstAgUnSort.List(lngLoop)
            frmMain.lstSorted1.ItemData(frmMain.lstSorted1.NewIndex) = frmMain.lstAgUnSort.ItemData(lngLoop)
        End If
    Next
    'Alle wekelijkse afspraken
    For lngLoop = 0 To frmMain.lstAgSorted.ListCount - 1
         frmMain.lstSorted1.AddItem frmMain.lstAgSorted.List(lngLoop)
            frmMain.lstSorted1.ItemData(frmMain.lstSorted1.NewIndex) = frmMain.lstAgSorted.ItemData(lngLoop)
    Next

    strTemp = Format(Now, "YYYYMMDD")
    If PaddMode = 0 Then
        'Oude afspraken. Dus alles voor vandaag
        For lngLoop = frmMain.lstSorted1.ListCount - 1 To 0 Step -1
            strIni = frmMain.lstSorted1.List(lngLoop)
            If strIni <> "" Then
                If val(Left(strIni, 8)) < val(strTemp) And val(Left(strIni, 8)) > 0 Then
                    Agenda_Convert strIni, agTemp
                    If Format(chkDatum, "YYYYMMDD") <> Format(agTemp.Datum, "YYYYMMDD") Then
                        frmMain.lstBox(2).AddItem Format(agTemp.Datum, "YYYYMM.DD dddd")
                        frmMain.lstBox(2).ItemData(frmMain.lstBox(2).NewIndex) = -1
                    End If
                    chkDatum = agTemp.Datum
                    strAbout = agTemp.About
                    If InStr(strAbout, Chr(13)) Then
                        strAbout = Mid(strAbout, 1, InStr(strAbout, Chr(13)) - 1)
                    End If
                    frmMain.lstBox(2).AddItem "    " & Format(agTemp.Datum, "HH:NN") & "-" & Format(agTemp.Tijd, "HH:NN") & " " & CStr(agTemp.Priority) & "   " & strAbout
                    frmMain.lstBox(2).ItemData(frmMain.lstBox(2).NewIndex) = frmMain.lstSorted1.ItemData(lngLoop)
                End If
            End If
        Next
    Else
        'Alle nieuwe afspraken incl. vandaag
        strCheck = ""
        For lngLoop = 0 To frmMain.lstSorted1.ListCount - 1
            strIni = frmMain.lstSorted1.List(lngLoop)
            If strIni <> "" And strCheck <> strIni Then
                If val(Left(strIni, 8)) >= val(strTemp) Then
                    Agenda_Convert strIni, agTemp
                    If Format(chkDatum, "YYYYMMDD") <> Format(agTemp.Datum, "YYYYMMDD") Then
                        frmMain.lstBox(2).AddItem Format(agTemp.Datum, "YYYYMM.DD dddd")
                        frmMain.lstBox(2).ItemData(frmMain.lstBox(2).NewIndex) = -1
                    End If
                    chkDatum = agTemp.Datum

                    strAbout = agTemp.About
                    If InStr(strAbout, Chr(13)) Then
                        strAbout = Mid(strAbout, 1, InStr(strAbout, Chr(13)) - 1)
                    End If
                    frmMain.lstBox(2).AddItem "    " & Format(agTemp.Datum, "HH:NN") & "-" & Format(agTemp.Tijd, "HH:NN") & " " & CStr(agTemp.Priority) & "   " & strAbout
                    frmMain.lstBox(2).ItemData(frmMain.lstBox(2).NewIndex) = frmMain.lstSorted1.ItemData(lngLoop)
                End If
            End If
            strCheck = strIni
        Next
    End If
    Agenda_Load -1
    intUndo = -1
    frmMain.txtMBox(1).SetFocus
End Sub

Public Sub Agenda_Load(intIndex As Integer)
    Dim strIni As String
    Dim agTemp As AgendaRecord
    Dim lngLoop As Long

    If frmMain.lstSorted1.List(intIndex) <> "" Then
        strIni = frmMain.lstAgUnSort.List(intIndex)
        Agenda_Convert strIni, agTemp
        frmMain.txtMBox(1).Text = agTemp.About
        Select Case agTemp.Priority
            Case 1
                PaddPrio = AgendaBut1
            Case 2
                PaddPrio = AgendaBut2
            Case 3
                PaddPrio = AgendaBut3
            Case 4
                PaddPrio = AgendaBut4
            Case 5
                PaddPrio = AgendaBut5
            Case 6
                PaddPrio = AgendaBut6
            Case 7
                PaddPrio = AgendaBut7
            Case Else
                PaddPrio = AgendaBut0
        End Select
        frmMain.imgBut(AgendaBut0).Picture = LoadPicture(myButtons(AgendaBut0))
        frmMain.imgBut(AgendaBut1).Picture = LoadPicture(myButtons(AgendaBut1))
        frmMain.imgBut(AgendaBut2).Picture = LoadPicture(myButtons(AgendaBut2))
        frmMain.imgBut(AgendaBut3).Picture = LoadPicture(myButtons(AgendaBut3))
        frmMain.imgBut(AgendaBut4).Picture = LoadPicture(myButtons(AgendaBut4))
        frmMain.imgBut(AgendaBut5).Picture = LoadPicture(myButtons(AgendaBut5))
        frmMain.imgBut(AgendaBut6).Picture = LoadPicture(myButtons(AgendaBut6))
        frmMain.imgBut(AgendaBut7).Picture = LoadPicture(myButtons(AgendaBut7))
        frmMain.imgBut(PaddPrio).Picture = LoadPicture(Mid(myButtons(PaddPrio), 1, Len(myButtons(PaddPrio)) - 4) & "a" & Right(myButtons(PaddPrio), 4))
        If agTemp.Mode = True Then
            frmMain.optMode(1).Value = True
            If agTemp.Maandag = True Then frmMain.chkPadd(0).Value = 1 Else frmMain.chkPadd(0).Value = 0
            If agTemp.Dinsdag = True Then frmMain.chkPadd(1).Value = 1 Else frmMain.chkPadd(1).Value = 0
            If agTemp.Woensdag = True Then frmMain.chkPadd(2).Value = 1 Else frmMain.chkPadd(2).Value = 0
            If agTemp.Donderdag = True Then frmMain.chkPadd(3).Value = 1 Else frmMain.chkPadd(3).Value = 0
            If agTemp.Vrijdag = True Then frmMain.chkPadd(4).Value = 1 Else frmMain.chkPadd(4).Value = 0
            If agTemp.Zaterdag = True Then frmMain.chkPadd(5).Value = 1 Else frmMain.chkPadd(5).Value = 0
            If agTemp.Zondag = True Then frmMain.chkPadd(6).Value = 1 Else frmMain.chkPadd(6).Value = 0
        Else
            frmMain.optMode(0).Value = True
            For lngLoop = 0 To 6
                frmMain.chkPadd(lngLoop).Value = False
            Next
        End If
    Else
'        frmMain.lblPadd(0).Caption = ""
        frmMain.txtMBox(1).Text = ""
        PaddPrio = AgendaBut0
        frmMain.imgBut(AgendaBut0).Picture = LoadPicture(myButtons(AgendaBut0))
        frmMain.imgBut(AgendaBut1).Picture = LoadPicture(myButtons(AgendaBut1))
        frmMain.imgBut(AgendaBut2).Picture = LoadPicture(myButtons(AgendaBut2))
        frmMain.imgBut(AgendaBut3).Picture = LoadPicture(myButtons(AgendaBut3))
        frmMain.imgBut(AgendaBut4).Picture = LoadPicture(myButtons(AgendaBut4))
        frmMain.imgBut(AgendaBut5).Picture = LoadPicture(myButtons(AgendaBut5))
        frmMain.imgBut(AgendaBut6).Picture = LoadPicture(myButtons(AgendaBut6))
        frmMain.imgBut(AgendaBut7).Picture = LoadPicture(myButtons(AgendaBut7))
        frmMain.imgBut(PaddPrio).Picture = LoadPicture(Mid(myButtons(PaddPrio), 1, Len(myButtons(PaddPrio)) - 4) & "a" & Right(myButtons(PaddPrio), 4))
        frmMain.optMode(0).Value = True
        For lngLoop = 0 To 6
            frmMain.chkPadd(lngLoop).Value = False
        Next
        PaddStart = Now
        PaddEnd = DateAdd("h", 1, PaddStart)
    End If
    Agenda_ShowDate

    Agenda_CheckMode
End Sub

Public Sub Agenda_PrintItem()
    Dim curTop As Long
    Dim curLeft As Long
    Dim curText As Long
    Dim curLines As Long
    Dim maxLines As Long
    Dim lngLoop As Long
    Dim strMessage As String
    Dim StrLast As String
    Dim StrChar As String

    curTop = 25 * Printer.TwipsPerPixelY
    curLeft = 25 * Printer.TwipsPerPixelY
    
    Printer.fontName = "Haettenschweiler"
    Printer.fontSize = 24
    curTop = curTop + Printer.TextHeight("LCARS TERMINAL") + (10 * Printer.TwipsPerPixelY)
    Printer.fontName = "Courier New"
    Printer.fontSize = 10
    curText = Printer.TextHeight("99gZ")
    maxLines = Int((Printer.ScaleHeight - curTop) / Int(curText * 1.2))
    curLines = 1
    
    curTop = 25 * Printer.TwipsPerPixelY
    Printer.fontName = "Haettenschweiler"
    Printer.fontSize = 24
    Printer.CurrentX = curLeft
    Printer.CurrentY = curTop
    Printer.Print "LCARS TERMINAL"
    Printer.CurrentX = Printer.ScaleWidth - curLeft - Printer.TextWidth(text_overviewC)
    Printer.CurrentY = curTop
    Printer.Print text_overviewC
    curTop = curTop + Printer.TextHeight("LCARS TERMINAL") + (10 * Printer.TwipsPerPixelY)
    Printer.fontName = "Courier New"
    Printer.fontSize = 10
    frmMain.lstUnsorted.Clear
    If frmMain.optMode(0).Value = True Then
        ' Gaat om een dag
        frmMain.lstUnsorted.AddItem "From....: " & Format(PaddStart, "YYYYMMDDHHNN")
        frmMain.lstUnsorted.AddItem "To......: " & Format(PaddEnd, "YYYYMMDDHHNN")
    Else
        ' gaat om een weekly
        strMessage = "Days....: "
        If frmMain.chkPadd(0).Value = "1" Then strMessage = strMessage & "Monday "
        If frmMain.chkPadd(1).Value = "1" Then strMessage = strMessage & "Tuesday "
        If frmMain.chkPadd(2).Value = "1" Then strMessage = strMessage & "Wednesday "
        If frmMain.chkPadd(3).Value = "1" Then strMessage = strMessage & "Thursday "
        If frmMain.chkPadd(4).Value = "1" Then strMessage = strMessage & "Friday "
        If frmMain.chkPadd(5).Value = "1" Then strMessage = strMessage & "Saturday "
        If frmMain.chkPadd(6).Value = "1" Then strMessage = strMessage & "Sunday "
        frmMain.lstUnsorted.AddItem strMessage
    End If
    strMessage = "Priority: "
    Select Case PaddPrio
        Case AgendaBut1
            strMessage = strMessage & "1"
        Case AgendaBut2
            strMessage = strMessage & "2"
        Case AgendaBut3
            strMessage = strMessage & "3"
        Case AgendaBut4
            strMessage = strMessage & "4"
        Case AgendaBut5
            strMessage = strMessage & "5"
        Case AgendaBut6
            strMessage = strMessage & "6"
        Case AgendaBut7
            strMessage = strMessage & "7"
        Case Else
            strMessage = strMessage & "0"
    End Select
    frmMain.lstUnsorted.AddItem strMessage
    strMessage = ""
    StrLast = "About...: "
    
    For lngLoop = 1 To Len(frmMain.txtMBox(1).Text)
        StrChar = Mid(frmMain.txtMBox(1).Text, lngLoop, 1)
        If StrChar = Chr(13) Then
            frmMain.lstUnsorted.AddItem strMessage & StrLast
            strMessage = "          "
            StrLast = ""
        ElseIf Len(strMessage & StrLast) > 80 Then
            frmMain.lstUnsorted.AddItem strMessage
            strMessage = "          "
            If StrChar <> Chr(10) Then
                If StrChar <> " " Then
                    StrLast = StrLast & StrChar
                Else
                    strMessage = strMessage & StrLast & " "
                    StrLast = ""
                End If
            End If
        ElseIf StrChar <> Chr(10) Then
            If StrChar <> " " Then
                StrLast = StrLast & StrChar
            Else
                strMessage = strMessage & StrLast & " "
                StrLast = ""
            End If
        End If
    Next
    frmMain.lstUnsorted.AddItem strMessage & StrLast
    
    For lngLoop = 0 To frmMain.lstUnsorted.ListCount - 1
        If curLines = maxLines Then
            Printer.EndDoc
            curTop = 25 * Printer.TwipsPerPixelY
            Printer.fontName = "Haettenschweiler"
            Printer.fontSize = 24
            Printer.CurrentX = curLeft
            Printer.CurrentY = curTop
            Printer.Print "LCARS TERMINAL"
            Printer.CurrentX = Printer.ScaleWidth - curLeft - Printer.TextWidth(text_overviewC)
            Printer.CurrentY = curTop
            Printer.Print text_overviewC
            curTop = curTop + Printer.TextHeight("LCARS TERMINAL") + (10 * Printer.TwipsPerPixelY)
            Printer.fontName = "Courier New"
            Printer.fontSize = 10
            curLines = 1
        End If
        Printer.CurrentX = curLeft
        Printer.CurrentY = curTop + (curLines * Int(curText * 1.2))
        Printer.Print frmMain.lstUnsorted.List(lngLoop)
        curLines = curLines + 1
    Next
    Printer.EndDoc
End Sub

Public Sub Agenda_PrintList()
    Dim curTop As Long
    Dim curLeft As Long
    Dim curText As Long
    Dim curLines As Long
    Dim maxLines As Long
    Dim lngLoop As Long

    curTop = 25 * Printer.TwipsPerPixelY
    curLeft = 25 * Printer.TwipsPerPixelY
    
    Printer.fontName = "Haettenschweiler"
    Printer.fontSize = 24
    curTop = curTop + Printer.TextHeight("LCARS TERMINAL") + (10 * Printer.TwipsPerPixelY)
    Printer.fontName = "Courier New"
    Printer.fontSize = 12
    curText = Printer.TextHeight("99gZ")
    maxLines = Int((Printer.ScaleHeight - curTop) / Int(curText * 1.2))
    curLines = 1
    
    curTop = 25 * Printer.TwipsPerPixelY
    Printer.fontName = "Haettenschweiler"
    Printer.fontSize = 24
    Printer.CurrentX = curLeft
    Printer.CurrentY = curTop
    Printer.Print "LCARS TERMINAL"
    Printer.CurrentX = Printer.ScaleWidth - curLeft - Printer.TextWidth(text_overviewC)
    Printer.CurrentY = curTop
    Printer.Print text_overviewC
    curTop = curTop + Printer.TextHeight("LCARS TERMINAL") + (10 * Printer.TwipsPerPixelY)
    Printer.fontName = "Courier New"
    Printer.fontSize = 12
    For lngLoop = 0 To frmMain.lstBox(2).ListCount - 1
        If curLines = maxLines Then
            Printer.EndDoc
            curTop = 25 * Printer.TwipsPerPixelY
            Printer.fontName = "Haettenschweiler"
            Printer.fontSize = 24
            Printer.CurrentX = curLeft
            Printer.CurrentY = curTop
            Printer.Print "LCARS TERMINAL"
            Printer.CurrentX = Printer.ScaleWidth - curLeft - Printer.TextWidth(text_overviewC)
            Printer.CurrentY = curTop
            Printer.Print text_overviewC
            curTop = curTop + Printer.TextHeight("LCARS TERMINAL") + (10 * Printer.TwipsPerPixelY)
            Printer.fontName = "Times"
            Printer.fontSize = 12
            curLines = 1
        End If
        Printer.CurrentX = curLeft
        Printer.CurrentY = curTop + (curLines * Int(curText * 1.2))
        Printer.Print frmMain.lstBox(2).List(lngLoop)
        curLines = curLines + 1
    Next
    Printer.EndDoc
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 Sub Agenda_Save()
    Dim strTemp As String
    Dim lngLoop As Long
    Dim strIni As String
    Dim lngCounter As Long
    
    If Check_Shareware = "" Then
        MsgBox RegisterText, vbInformation, "LCARS Terminal"
    End If

    strTemp = ""
    If frmMain.optMode(0).Value = True Then
        strTemp = strTemp & Format(PaddStart, "YYYYMMDDHHNN") & Chr(1)
        strTemp = strTemp & Format(PaddEnd, "YYYYMMDDHHNN") & Chr(1)
    Else
        strTemp = strTemp & "00000000" & Format(PaddStart, "HHNN") & Chr(1)
        strTemp = strTemp & "00000000" & Format(PaddEnd, "HHNN") & Chr(1)
    End If
    strTemp = strTemp & frmMain.txtMBox(1).Text & Chr(1)
    If frmMain.optMode(0).Value = True Then
        strTemp = strTemp & "0" & Chr(1)
    Else
        strTemp = strTemp & "1" & Chr(1)
    End If
    Select Case PaddPrio
        Case AgendaBut1
            strTemp = strTemp & "1" & Chr(1)
        Case AgendaBut2
            strTemp = strTemp & "2" & Chr(1)
        Case AgendaBut3
            strTemp = strTemp & "3" & Chr(1)
        Case AgendaBut4
            strTemp = strTemp & "4" & Chr(1)
        Case AgendaBut5
            strTemp = strTemp & "5" & Chr(1)
        Case AgendaBut6
            strTemp = strTemp & "6" & Chr(1)
        Case AgendaBut7
            strTemp = strTemp & "7" & Chr(1)
        Case Else
            strTemp = strTemp & "0" & Chr(1)
    End Select
    If frmMain.optMode(0).Value = True Then
        strTemp = strTemp & "0" & Chr(1)
        strTemp = strTemp & "0" & Chr(1)
        strTemp = strTemp & "0" & Chr(1)
        strTemp = strTemp & "0" & Chr(1)
        strTemp = strTemp & "0" & Chr(1)
        strTemp = strTemp & "0" & Chr(1)
        strTemp = strTemp & "0" & Chr(1)
    Else
        strTemp = strTemp & CStr(frmMain.chkPadd(0).Value) & Chr(1)
        strTemp = strTemp & CStr(frmMain.chkPadd(1).Value) & Chr(1)
        strTemp = strTemp & CStr(frmMain.chkPadd(2).Value) & Chr(1)
        strTemp = strTemp & CStr(frmMain.chkPadd(3).Value) & Chr(1)
        strTemp = strTemp & CStr(frmMain.chkPadd(4).Value) & Chr(1)
        strTemp = strTemp & CStr(frmMain.chkPadd(5).Value) & Chr(1)
        strTemp = strTemp & CStr(frmMain.chkPadd(6).Value) & Chr(1)
    End If
    
    If intUndo >= 0 Then
        If strTemp = frmMain.lstAgUnSort.List(intUndo) Then
            Agenda_Load -1
            Overview_Load ' frmMain.MList1
            Exit Sub
        End If
        frmMain.lstAgUnSort.RemoveItem intUndo
    End If
    frmMain.lstAgUnSort.AddItem strTemp
    
    lngCounter = 0
    For lngLoop = 0 To frmMain.lstAgUnSort.ListCount - 1
        lngCounter = lngCounter + 1
        INI_WriteKey "AGENDA", CStr(lngCounter), Database_Encrypt(frmMain.lstAgUnSort.List(lngLoop)), strProgramdir & "\padd\agenda.ini"
    Next
    INI_WriteKey "AGENDA", "ID", CStr(lngCounter), strProgramdir & "\padd\agenda.ini"
    
    Agenda_ReloadFull frmMain.lstAgUnSort, frmMain.lstAgSorted, frmMain.lstWeekly, frmMain.lstAgenda
    Agenda_Init
    Overview_Load 'frmMain.MList1


End Sub

Public Sub Agenda_ShowDate()
    On Error Resume Next
    frmMain.lblBox(StartHour).Caption = Format(PaddStart, "hh")
    frmMain.lblBox(StartMin).Caption = Format(PaddStart, "nn")
    frmMain.lblBox(EndHour).Caption = Format(PaddEnd + 1, "hh")
    frmMain.lblBox(EndMin).Caption = Format(PaddEnd, "nn")
    If frmMain.optMode(0).Value = True Then
        frmMain.lblBox(ModeDay).Caption = Format(PaddStart, "dd")
        frmMain.lblBox(ModeMonth).Caption = UCase(Format(PaddStart, "mmmm"))
        frmMain.lblBox(ModeYear).Caption = Format(PaddStart, "yyyy")
    Else
        frmMain.lblBox(ModeDay).Caption = "--"
        frmMain.lblBox(ModeMonth).Caption = "--"
        frmMain.lblBox(ModeYear).Caption = "--"
    End If
End Sub

Public Sub Calendar_Init()
    Dim lngMaand As Long
    Dim strMaand As String
    Dim lngLoop As Long
    Dim lngDagen As Long
    Dim strIni As String
    Dim booIni As Boolean

    frmMain.lstBox(2).Clear
    For lngMaand = 1 To 12
        Select Case lngMaand
            Case 1, 3, 5, 7, 8, 10, 12
                lngDagen = 31
            Case 2
                lngDagen = 29
            Case Else
                lngDagen = 30
        End Select
        booIni = INI_GetKey("CALENDAR", "mon" + Format(lngMaand, "00"), strProgramdir & strThemedir & strThemeName & ".skn")
        strMaand = iniValue
        For lngLoop = 1 To lngDagen
            strIni = Format(lngMaand, "00") & Format(lngLoop, "00")
            booIni = INI_GetKey("CALENDAR", strIni, strProgramdir & "\padd\calendar.ini")
            If booIni = True And iniValue <> "" Then
                frmMain.lstBox(2).AddItem Format(lngLoop, "00") + " " + strMaand + "  " + Database_Decrypt(iniValue)
                frmMain.lstBox(2).ItemData(frmMain.lstBox(2).NewIndex) = val("3" & strIni)
            End If
        Next
    Next
    booIni = INI_GetKey("CALENDAR", "load", strProgramdir & strThemedir & strThemeName & ".skn")
    intUndo = -1
    strLoadClick = iniValue
End Sub

Public Sub Calendar_Load(Maand As Integer)
    Dim lngLoop As Long
    Dim lngDagen As Long
    Dim strIni As String
    Dim booIni As Boolean
    Dim MyDate, MyShortDate
    
    
    frmMain.picMonth.Picture = LoadPicture(strProgramdir & strThemedir & strProgram & "\calmon" + Format(Maand, "00") + ".bmp")
    frmMain.picMonth.Visible = True
    
    intMaand = Maand
    Select Case Maand
        Case 1, 3, 5, 7, 8, 10, 12
            lngDagen = 31
        Case 2
            lngDagen = 29
        Case Else
            lngDagen = 30
    End Select
    For lngLoop = 1 To lngDagen
        strIni = Format(intMaand, "00") & Format(lngLoop, "00")
        booIni = INI_GetKey("CALENDAR", strIni, strProgramdir & "\padd\calendar.ini")
        If booIni = True And iniValue <> "" Then
            frmMain.txtBox(lngLoop).Text = Database_Decrypt(iniValue)
        Else
            frmMain.txtBox(lngLoop).Text = ""
        End If
        frmMain.txtBox(lngLoop).Visible = True
        frmMain.txtBox(lngLoop).TabIndex = lngLoop + 1
        frmMain.txtBox(lngLoop).TabStop = True
        'MyDate = lngLoop & "/" & Format(intMaand, "00") & "/" & Format(Now, "yyyy") ' Define date.
        'MyShortDate = CDate(MyDate)   ' Convert to Date data type.

        'frmMain.txtBox(lngLoop).ToolTipText = Format(MyShortDate, "dddd")
    Next
    For lngLoop = lngDagen + 1 To 31
        frmMain.txtBox(lngLoop).Visible = False
        frmMain.txtBox(lngLoop).TabStop = False
        frmMain.txtBox(lngLoop).ToolTipText = ""
    Next
End Sub

Public Sub Calendar_Print(Maand As Integer)
    Dim curTop As Long
    Dim curLeft As Long
    Dim curWidth As Long
    Dim curOffset As Long
    Dim curText As Long
    Dim lngLoop As Long
    Dim strTEXT As String
    Dim lngDagen As Long
    Dim lngCount As Long
    Dim strIni As String
    Dim booIni As Boolean
    Dim strMaand As String
    
    curTop = 25 * Printer.TwipsPerPixelY
    curLeft = 25 * Printer.TwipsPerPixelY
    
    booIni = INI_GetKey("CALENDAR", "month" + Format(Maand, "00"), strProgramdir & strThemedir & strThemeName & ".skn")
    strMaand = UCase(iniValue)
    frmMain.picBig.Picture = LoadPicture(strProgramdir + strThemedir + strProgram + "\calmon" + Format(Maand, "00") + ".jpg")
    Printer.fontName = "Haettenschweiler"
    Printer.fontSize = 24
    Printer.CurrentX = curLeft
    Printer.CurrentY = curTop
    Printer.Print "LCARS TERMINAL"
    Printer.CurrentX = Printer.ScaleWidth - curLeft - Printer.TextWidth(strMaand)
    Printer.CurrentY = curTop
    Printer.Print strMaand
    curTop = curTop + Printer.TextHeight("LCARS TERMINAL") + (10 * Printer.TwipsPerPixelY)
    lngLoop = Printer.ScaleWidth - (curLeft * 2)
    Printer.PaintPicture frmMain.picBig.Picture, curLeft, curTop, lngLoop, Int((lngLoop * 768) / 1024)
    curTop = curTop + Int((lngLoop * 768) / 1024) + (10 * Printer.TwipsPerPixelY)
    curOffset = Int((Printer.ScaleHeight - curTop - (50 * Printer.TwipsPerPixelY)) / 16)
    curLeft = curLeft + Int(lngLoop / 2)
    curWidth = Int(lngLoop / 2) - Printer.TextWidth("9999")
    curText = Printer.TextWidth("999")
    
    Select Case Maand
        Case 1, 3, 5, 7, 8, 10, 12
            lngDagen = 31
            lngCount = 14
        Case 2
            lngDagen = 29
            lngCount = 12
        Case Else
            lngDagen = 30
            lngCount = 13
    End Select
    
    
    For lngLoop = 0 To 15
        Printer.fontName = "Haettenschweiler"
        Printer.fontSize = 12
        strTEXT = CStr(lngLoop + 1)
        Printer.CurrentX = (25 * Printer.TwipsPerPixelX) + Printer.TextWidth("99") - Printer.TextWidth(strTEXT)
        Printer.CurrentY = curTop + (lngLoop * curOffset)
        Printer.Print strTEXT
        If lngLoop <= lngCount Then
            strTEXT = CStr(lngLoop + 17)
            Printer.CurrentX = curLeft + Printer.TextWidth("99") - Printer.TextWidth(strTEXT)
            Printer.CurrentY = curTop + (lngLoop * curOffset)
            Printer.Print strTEXT
        End If
        
        Printer.fontName = "Arial"
        Printer.fontSize = 10
        
        strIni = Format(Maand, "00") & Format(lngLoop + 1, "00")
        booIni = INI_GetKey("CALENDAR", strIni, strProgramdir & "\padd\calendar.ini")
        If booIni = True And iniValue <> "" Then
            strTEXT = Database_Decrypt(iniValue)
            While Printer.TextWidth(strTEXT) > curWidth
                strTEXT = Left(strTEXT, Len(strTEXT) - 1)
            Wend
            Printer.CurrentX = (25 * Printer.TwipsPerPixelX) + curText
            Printer.CurrentY = curTop + (lngLoop * curOffset)
            Printer.Print strTEXT
        End If
    
        If lngLoop < lngCount Then
            strIni = Format(Maand, "00") & Format(lngLoop + 17, "00")
            booIni = INI_GetKey("CALENDAR", strIni, strProgramdir & "\padd\calendar.ini")
            If booIni = True And iniValue <> "" Then
                strTEXT = Trim(Database_Decrypt(iniValue))
                While Printer.TextWidth(strTEXT) > curWidth
                    strTEXT = Left(strTEXT, Len(strTEXT) - 1)
                Wend
                Printer.CurrentX = curLeft + curText
                Printer.CurrentY = curTop + (lngLoop * curOffset)
                Printer.Print strTEXT
            End If
        End If
    
    Next
    Printer.EndDoc
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 Sub Logbook_Delete()
    Dim lngLoop As Long
    Dim strIni As String
    Dim booIni As Boolean
    
    'If frmMain.txtBox(1).Text = "" Then
    If frmMain.lblBox(1).Caption = "" Then
        Exit Sub
    End If
    If intUndo >= 0 Then
        If (MsgBox("Are you sure to delete this item?", vbYesNo, "LCARS Terminal") = vbYes) Then
            strIni = Mid(frmMain.lstSorted1.List(intUndo), 1, InStr(frmMain.lstSorted1.List(intUndo), Chr(1)) - 1)
            frmMain.lstSorted1.RemoveItem intUndo
            booIni = INI_GetKey("PADD", "Logbook", strProgramdir & "\padd\directories.ini")
            Kill iniValue & "\" & strIni
            Logbook_Init ""
            Logbook_Load -1
            intUndo = -1
            Overview_Load
        End If
    End If
End Sub

Public Sub Logbook_Init(logfind As String)
    Dim lngLoop As Long
    Dim booIni As Boolean
    Dim strIni As String
    Dim strTitel As String
    Dim strTEXT As String
    Dim fptr
    Dim strlineA As String
    Dim strlineB As String
    Dim strlineC As String
    Dim strCheck As String
    Dim strFind As String
    Dim lngFind As Long
    
    strCheck = Check_Shareware

    'Nieuwe normale logbook inladen.
    frmMain.lstSorted1.Clear
    'frmMain.File1.Pattern = "*.not"
    booIni = INI_GetKey("PADD", "Logbook", strProgramdir & "\padd\directories.ini")
    frmMain.File1.Path = CStr(iniValue)
    frmMain.File1.Refresh
    lngFind = 0
    For lngLoop = 0 To frmMain.File1.ListCount - 1
        fptr = freefile
        strTitel = frmMain.File1.List(lngLoop)
        Open frmMain.File1.Path & "\" & strTitel For Input As #fptr
        Line Input #fptr, strTEXT
        If logfind <> "" Then
            strFind = strTEXT
            While Not EOF(fptr)
                Line Input #fptr, strlineA
                strFind = strFind & strlineA
            Wend
        End If
        Close #fptr
        If (strCheck = "" And lngLoop < 10) Or strCheck <> "" Then
            If logfind = "" Then
                frmMain.lstSorted1.AddItem strTitel & Chr(1) & strTEXT
                frmMain.lstSorted1.ItemData(frmMain.lstSorted1.NewIndex) = lngLoop
            Else
                If InStr(1, strFind, logfind, vbTextCompare) > 0 Then
                    frmMain.lstSorted1.AddItem strTitel & Chr(1) & strTEXT
                    frmMain.lstSorted1.ItemData(frmMain.lstSorted1.NewIndex) = lngFind
                    lngFind = lngFind + 1
                End If
            End If
        End If
    Next
    
    frmMain.lstBox(2).Clear
    For lngLoop = frmMain.lstSorted1.ListCount - 1 To 0 Step -1
        strIni = frmMain.lstSorted1.List(lngLoop)
        If strIni <> "" Then
            strTitel = Mid(strIni, 1, 6) & "." & Mid(strIni, 7, 2) & " " & Mid(strIni, 9, 2) & ":" & Mid(strIni, 11, 2) & ":" & Mid(strIni, 13, 2)
            strIni = Mid(strIni, InStr(strIni, Chr(1)) + 1)
            frmMain.lstBox(2).AddItem strTitel
            frmMain.lstBox(2).ItemData(frmMain.lstBox(2).NewIndex) = frmMain.lstSorted1.ItemData(lngLoop)
            frmMain.lstBox(2).AddItem "   " & strIni
            frmMain.lstBox(2).ItemData(frmMain.lstBox(2).NewIndex) = frmMain.lstSorted1.ItemData(lngLoop)
        End If
    Next
    booIni = INI_GetKey("LOGBOOK", "load", strProgramdir & strThemedir & strThemeName & ".skn")
    strLoadClick = iniValue
    intUndo = -1

End Sub

Public Sub Logbook_Load(intIndex As Integer)
    Dim strIni As String
    Dim fptr
    Dim strFile As String
    Dim booIni As Boolean

    If frmMain.lstSorted1.List(intIndex) <> "" Then
        strIni = frmMain.lstSorted1.List(intIndex)
        frmMain.lblBox(1).Caption = Mid(strIni, 1, 6) & "." & Mid(strIni, 7, 2) & " " & Mid(strIni, 9, 2) & ":" & Mid(strIni, 11, 2) & ":" & Mid(strIni, 13, 2)
        strFile = Mid(strIni, 1, InStr(strIni, Chr(1)) - 1)
        fptr = freefile
        booIni = INI_GetKey("PADD", "Logbook", strProgramdir & "\padd\directories.ini")
        Open iniValue & "\" & strFile For Input As #fptr
        frmMain.txtMBox(1).Text = ""
        While Not EOF(fptr)
            Line Input #fptr, strFile
            frmMain.txtMBox(1).Text = frmMain.txtMBox(1).Text & strFile & vbCrLf
        Wend
        Close #fptr
    Else
        If (intIndex = -1) Then
            frmMain.lblBox(1).Caption = ""
        Else
            frmMain.lblBox(1).Caption = Format(Now, "yyyymm.dd Hh:Nn:Ss")
        End If
        frmMain.txtMBox(1).Text = ""
    End If
End Sub

Public Sub Logbook_Save()
    Dim strTemp As String
    Dim lngLoop As Long
    Dim strIni As String
    Dim strFile As String
    Dim booIni As Boolean
    Dim fptr
    
    If Check_Shareware = "" Then
        MsgBox RegisterText, vbInformation, "LCARS Terminal"
    End If

    strIni = frmMain.lblBox(1).Caption
    If strIni = "" Then strIni = Format(Now, "YYYYMM.DD HH:NN:SS")
    strFile = Mid(strIni, 1, 6) & Mid(strIni, 8, 2) & Mid(strIni, 11, 2) & Mid(strIni, 14, 2) & Mid(strIni, 17, 2) & ".log"
    fptr = freefile
    booIni = INI_GetKey("PADD", "Logbook", strProgramdir & "\padd\directories.ini")
    Open iniValue & "\" & strFile For Output As #fptr
    strTemp = frmMain.txtMBox(1).Text
    If strTemp = "" Then frmMain.txtMBox(1).Text = "---"
    Print #fptr, frmMain.txtMBox(1).Text
    Close #fptr
    Logbook_Init ""
    Logbook_Load -1
    intUndo = -1
    Overview_Load
End Sub

Public Sub Notes_Delete()
    Dim lngLoop As Long
    Dim strIni As String
    Dim booIni As Boolean
    
    If frmMain.txtBox(1).Text = "" Then
        Exit Sub
    End If
    If intUndo >= 0 Then
        If (MsgBox("Are you sure to delete this item?", vbYesNo, "LCARS Terminal") = vbYes) Then
            strIni = Mid(frmMain.lstSorted1.List(intUndo), InStr(frmMain.lstSorted1.List(intUndo), Chr(1)) + 1)
            frmMain.lstSorted1.RemoveItem intUndo
            booIni = INI_GetKey("PADD", "Notes", strProgramdir & "\padd\directories.ini")
            Kill iniValue & "\" & strIni
            Notes_Init
            Notes_Load -1
            intUndo = -1
            Overview_Load
        End If
    End If
End Sub

Public Sub Notes_Init()
    Dim lngLoop As Long
    Dim booIni As Boolean
    Dim strIni As String
    Dim strTitel As String
    Dim fptr
    Dim strCheck As String
    
    'Nieuwe normale notes inladen.
    frmMain.lstSorted1.Clear
    'frmMain.File1.Pattern = "*.not"
    booIni = INI_GetKey("PADD", "Notes", strProgramdir & "\padd\directories.ini")
    frmMain.File1.Path = iniValue
    frmMain.File1.Refresh
    
    strCheck = Check_Shareware
    
    For lngLoop = 0 To frmMain.File1.ListCount - 1
        fptr = freefile
        Open frmMain.File1.Path & "\" & frmMain.File1.List(lngLoop) For Input As #fptr
        Line Input #fptr, strTitel
        Close #fptr
        If (strCheck = "" And lngLoop < 10) Or strCheck <> "" Then
            frmMain.lstSorted1.AddItem strTitel & Chr(1) & frmMain.File1.List(lngLoop)
            frmMain.lstSorted1.ItemData(frmMain.lstSorted1.NewIndex) = lngLoop
        End If
    Next
    
    frmMain.lstBox(2).Clear
    For lngLoop = 0 To frmMain.lstSorted1.ListCount - 1
        strIni = frmMain.lstSorted1.List(lngLoop)
        If strIni <> "" Then
            frmMain.lstBox(2).AddItem Mid(strIni, 1, InStr(strIni, Chr(1)) - 1)
            frmMain.lstBox(2).ItemData(frmMain.lstBox(2).NewIndex) = frmMain.lstSorted1.ItemData(lngLoop)
        End If
    Next
    booIni = INI_GetKey("NOTES", "load", strProgramdir & strThemedir & strThemeName & ".skn")
    strLoadClick = iniValue
    intUndo = -1
End Sub

Public Sub Notes_Load(intIndex As Integer)
    Dim strIni As String
    Dim fptr
    Dim strFile As String
    Dim booIni As Boolean

    If frmMain.lstSorted1.List(intIndex) <> "" Then
        strIni = frmMain.lstSorted1.List(intIndex)
        frmMain.txtBox(1).Text = Mid(strIni, 1, InStr(strIni, Chr(1)) - 1)
        strFile = Mid(strIni, InStr(strIni, Chr(1)) + 1)
        fptr = freefile
        booIni = INI_GetKey("PADD", "Notes", strProgramdir & "\padd\directories.ini")
        Open iniValue & "\" & strFile For Input As #fptr
        Line Input #fptr, strFile
        frmMain.txtMBox(1).Text = ""
        While Not EOF(fptr)
            Line Input #fptr, strFile
            frmMain.txtMBox(1).Text = frmMain.txtMBox(1).Text & strFile & vbCrLf
        Wend
        Close #fptr
    Else
        frmMain.txtBox(1).Text = ""
        frmMain.txtMBox(1).Text = ""
    End If
End Sub

Public Sub Notes_Save()
    Dim strTemp As String
    Dim lngLoop As Long
    Dim strIni As String
    Dim strFile As String
    Dim booIni As Boolean
    Dim fptr
    
    If Check_Shareware = "" Then
        MsgBox RegisterText, vbInformation, "LCARS Terminal"
    End If

    If frmMain.txtBox(1).Text <> "" Then
        strTemp = frmMain.txtBox(1).Text
    Else
        strTemp = "New Note"
    End If
    
    If intUndo >= 0 Then
        strFile = Mid(frmMain.lstSorted1.List(intUndo), InStr(frmMain.lstSorted1.List(intUndo), Chr(1)) + 1)
    Else
        strFile = Format(Now, "yyyymmddHhNnSs") & ".not"
    End If
    fptr = freefile
    booIni = INI_GetKey("PADD", "Notes", strProgramdir & "\padd\directories.ini")
    Open iniValue & "\" & strFile For Output As #fptr
    Print #fptr, strTemp
    strTemp = frmMain.txtMBox(1).Text
    If strTemp = "" Then frmMain.txtMBox(1).Text = "---"
    Print #fptr, frmMain.txtMBox(1).Text
    Close #fptr
    Notes_Init
    Notes_Load -1
    intUndo = -1
    Overview_Load
End Sub

Public Sub Overview_Load()
    Dim Datum As Date
    Dim lngCount As Long
    Dim lngHeader As Long
    Dim strKey As String
    Dim strTitel As String
    Dim strTemp As String
    Dim lngLoop As Long
    Dim booIni As Boolean
    Dim agTemp As AgendaRecord
    Dim fptr
    
    frmMain.lstBox(1).Clear
    Datum = Now
    
    'Agenda
    lngCount = 0
    frmMain.lstBox(1).AddItem text_overviewC & "  "
    frmMain.lstBox(1).ItemData(frmMain.lstBox(1).NewIndex) = 1
    'myLst.ItemForeColor(myLst.NewIndex) = myLst.ForeColor
    'myLst.ItemBackColor(myLst.NewIndex) = myLst.BackColor
    'myLst.ItemHiliteColor(myLst.NewIndex) = myLst.BackColor
    'myLst.ItemHiliteTextColor(myLst.NewIndex) = myLst.ForeColor
    lngHeader = frmMain.lstBox(1).NewIndex
    For lngLoop = 0 To frmMain.lstAgenda.ListCount - 1
        strTemp = frmMain.lstAgenda.List(lngLoop)
        If InStr(strTemp, Chr(1)) Then
            Agenda_Convert strTemp, agTemp
            frmMain.lstBox(1).AddItem "    " & Format(agTemp.Datum, "HH:NN") & "-" & Format(agTemp.Tijd, "HH:NN") & " " & CStr(agTemp.Priority) & "   " & agTemp.About
            frmMain.lstBox(1).ItemData(frmMain.lstBox(1).NewIndex) = val("1" & CStr(frmMain.lstAgenda.ItemData(lngLoop)))
            'myLst.ItemBackColor(myLst.NewIndex) = myLst.BackColor
            'myLst.ItemForeColor(myLst.NewIndex) = myLst.HiliteColor
            lngCount = lngCount + 1
        ElseIf strTemp <> "" Then
            frmMain.lstBox(1).AddItem "  " & strTemp
            frmMain.lstBox(1).ItemData(frmMain.lstBox(1).NewIndex) = 1
            'myLst.ItemBackColor(myLst.NewIndex) = myLst.BackColor
            'myLst.ItemForeColor(myLst.NewIndex) = myLst.HiliteTextColor
        End If
    Next
    frmMain.lstBox(1).List(lngHeader) = frmMain.lstBox(1).List(lngHeader) & "(" & CStr(lngCount) & ")"
    
    
    'CALENDAR
    lngCount = 0
    frmMain.lstBox(1).AddItem text_overviewA & "  "
    frmMain.lstBox(1).ItemData(frmMain.lstBox(1).NewIndex) = 3
    'myLst.ItemForeColor(myLst.NewIndex) = myLst.ForeColor
    'myLst.ItemBackColor(myLst.NewIndex) = myLst.BackColor
    'myLst.ItemHiliteColor(myLst.NewIndex) = myLst.BackColor
    'myLst.ItemHiliteTextColor(myLst.NewIndex) = myLst.ForeColor
    lngHeader = frmMain.lstBox(1).NewIndex
    For lngLoop = 0 To 9
        strKey = Format(DateAdd("D", lngLoop, Datum), "MMDD")
        booIni = INI_GetKey("CALENDAR", strKey, strProgramdir & "\padd\calendar.ini")
        If booIni Then
            If iniValue <> "" Then
                frmMain.lstBox(1).AddItem "  " & Format(DateAdd("D", lngLoop, Datum), "YYYYMM.DD") & " " & Database_Decrypt(iniValue)
                frmMain.lstBox(1).ItemData(frmMain.lstBox(1).NewIndex) = val("3" & strKey)
                'myLst.ItemBackColor(myLst.NewIndex) = myLst.BackColor
                'myLst.ItemForeColor(myLst.NewIndex) = myLst.HiliteColor
                lngCount = lngCount + 1
            End If
        End If
    Next
    frmMain.lstBox(1).List(lngHeader) = frmMain.lstBox(1).List(lngHeader) & "(" & CStr(lngCount) & ")"
    
    
    
    'Email
    lngCount = 0
    frmMain.lstBox(1).AddItem "E-Mail  "
    frmMain.lstBox(1).ItemData(frmMain.lstBox(1).NewIndex) = 4
    'myLst.ItemForeColor(myLst.NewIndex) = myLst.ForeColor
    'myLst.ItemBackColor(myLst.NewIndex) = myLst.BackColor
    'myLst.ItemHiliteColor(myLst.NewIndex) = myLst.BackColor
    'myLst.ItemHiliteTextColor(myLst.NewIndex) = myLst.ForeColor
    lngHeader = frmMain.lstBox(1).NewIndex
    frmMain.Dir1.Path = strProgramdir & "\email"
    frmMain.Dir1.Refresh
    For lngLoop = 0 To frmMain.Dir1.ListCount - 1
        Select Case Mid(frmMain.Dir1.List(lngLoop), Len(frmMain.Dir1.Path) + 2)
            Case "0"
                strTemp = defIn
            Case "1"
                strTemp = defOut
            Case "2"
                strTemp = defSnd
            Case "3"
                strTemp = defDel
            Case Else
                strTemp = Mid(frmMain.Dir1.List(lngLoop), Len(frmMain.Dir1.Path) + 2)
        End Select
        frmMain.lstBox(1).AddItem "  " & strTemp
        frmMain.lstBox(1).ItemData(frmMain.lstBox(1).NewIndex) = val("4" & Format(lngLoop, "00000"))
        'myLst.ItemBackColor(myLst.NewIndex) = myLst.BackColor
        'myLst.ItemForeColor(myLst.NewIndex) = myLst.HiliteColor
        lngCount = lngCount + 1
    Next
    frmMain.lstBox(1).List(lngHeader) = frmMain.lstBox(1).List(lngHeader) & "(" & CStr(lngCount) & ")"
    
    
    'ToDO
    lngCount = 0
    frmMain.lstBox(1).AddItem text_overviewB & "  "
    frmMain.lstBox(1).ItemData(frmMain.lstBox(1).NewIndex) = 7
    lngHeader = frmMain.lstBox(1).NewIndex
    
    frmMain.lstSorted2.Clear
    'frmMain.File1.Pattern = "*.tod"
    booIni = INI_GetKey("PADD", "Todo", strProgramdir & "\padd\directories.ini")
    frmMain.File1.Path = iniValue
    frmMain.File1.Refresh
    
    For lngLoop = 0 To frmMain.File1.ListCount - 1
        fptr = freefile
        booIni = INI_GetKey("PADD", "Todo", strProgramdir & "\padd\directories.ini")
        Open iniValue & "\" & frmMain.File1.List(lngLoop) For Input As #fptr
        Line Input #fptr, strKey
        Line Input #fptr, strTitel
        Close #fptr
        If Left(strKey, 1) = "0" Then
            frmMain.lstSorted2.AddItem strKey & strTitel & Chr(1) & frmMain.File1.List(lngLoop)
            frmMain.lstSorted2.ItemData(frmMain.lstSorted2.NewIndex) = lngLoop
        End If
    Next
    For lngLoop = 0 To frmMain.lstSorted2.ListCount - 1
        strKey = frmMain.lstSorted2.List(lngLoop)
        frmMain.lstBox(1).AddItem "  " & Mid(strKey, 2, InStr(strKey, Chr(1)) - 2)
        frmMain.lstBox(1).ItemData(frmMain.lstBox(1).NewIndex) = val("7" & CStr(frmMain.lstSorted2.ItemData(lngLoop)))
        lngCount = lngCount + 1
    Next
    
    frmMain.lstBox(1).List(lngHeader) = frmMain.lstBox(1).List(lngHeader) & "(" & CStr(lngCount) & ")"
    
End Sub

Public Sub Padd_Convert()
    Dim lngLoop As Long
    Dim booIni As Boolean
    Dim strIni As String
    Dim strTitel As String
    Dim strTEXT As String
    Dim lngMax As Long
    Dim fptr
    Dim lngMaand As Long
    Dim strMaand As String
    Dim lngDagen As Long
    Dim bookRec As BookRecord
    
    On Error Resume Next
    MkDir strProgramdir & "\Padd"
    MkDir strProgramdir & "\Padd\Addressbook"
    MkDir strProgramdir & "\Padd\Logbook"
    MkDir strProgramdir & "\Padd\Notes"
    MkDir strProgramdir & "\Padd\Todo"
    
    booIni = INI_GetKey("PADD", "Logbook", strProgramdir & "\padd\directories.ini")
    If booIni = False Then
        INI_WriteKey "PADD", "Logbook", strProgramdir & "\Padd\Logbook", strProgramdir & "\padd\directories.ini"
    End If
    booIni = INI_GetKey("PADD", "Notes", strProgramdir & "\padd\directories.ini")
    If booIni = False Then
        INI_WriteKey "PADD", "Notes", strProgramdir & "\Padd\Notes", strProgramdir & "\padd\directories.ini"
    End If
    booIni = INI_GetKey("PADD", "Todo", strProgramdir & "\padd\directories.ini")
    If booIni = False Then
        INI_WriteKey "PADD", "Todo", strProgramdir & "\Padd\Todo", strProgramdir & "\padd\directories.ini"
    End If
    
    
    
    'Kijk of er oude addressbook items zijn en converteer deze naar de nieuwe.
    booIni = INI_GetKey("BOOK", "ID", strProgramdir & "\padd-data.ini")
    If booIni Then
        lngMax = iniValue
        For lngLoop = 0 To lngMax - 1
            strIni = CStr(lngLoop + 1)
            booIni = INI_GetKey("BOOK", strIni, strProgramdir & "\padd-data.ini")
            If booIni = True And iniValue <> "" Then
                fptr = freefile
                Open strProgramdir & "\Padd\Addressbook\" & lngLoop & ".dat" For Output As #fptr
                strTEXT = Database_Decrypt(iniValue)
                lngMaand = "1"
                lngDagen = InStr(lngMaand, strTEXT, Chr(1))
                bookRec.Achternaam = Mid(strTEXT, lngMaand, lngDagen - lngMaand)
                lngMaand = lngDagen + 1
                lngDagen = InStr(lngMaand, strTEXT, Chr(1))
                bookRec.Voorletters = Mid(strTEXT, lngMaand, lngDagen - lngMaand)
                lngMaand = lngDagen + 1
                lngDagen = InStr(lngMaand, strTEXT, Chr(1))
                bookRec.Displaynaam = Mid(strTEXT, lngMaand, lngDagen - lngMaand)
                lngMaand = lngDagen + 1
                lngDagen = InStr(lngMaand, strTEXT, Chr(1))
                bookRec.Adres1 = Mid(strTEXT, lngMaand, lngDagen - lngMaand)
                lngMaand = lngDagen + 1
                lngDagen = InStr(lngMaand, strTEXT, Chr(1))
                bookRec.Adres2 = Mid(strTEXT, lngMaand, lngDagen - lngMaand)
                lngMaand = lngDagen + 1
                lngDagen = InStr(lngMaand, strTEXT, Chr(1))
                bookRec.Postcode = Mid(strTEXT, lngMaand, lngDagen - lngMaand)
                lngMaand = lngDagen + 1
                lngDagen = InStr(lngMaand, strTEXT, Chr(1))
                bookRec.Plaats = Mid(strTEXT, lngMaand, lngDagen - lngMaand)
                lngMaand = lngDagen + 1
                lngDagen = InStr(lngMaand, strTEXT, Chr(1))
                bookRec.Provincie = Mid(strTEXT, lngMaand, lngDagen - lngMaand)
                lngMaand = lngDagen + 1
                lngDagen = InStr(lngMaand, strTEXT, Chr(1))
                bookRec.Land = Mid(strTEXT, lngMaand, lngDagen - lngMaand)
                lngMaand = lngDagen + 1
                lngDagen = InStr(lngMaand, strTEXT, Chr(1))
                bookRec.Telefoon = Mid(strTEXT, lngMaand, lngDagen - lngMaand)
                lngMaand = lngDagen + 1
                lngDagen = InStr(lngMaand, strTEXT, Chr(1))
                bookRec.Fax = Mid(strTEXT, lngMaand, lngDagen - lngMaand)
                lngMaand = lngDagen + 1
                lngDagen = InStr(lngMaand, strTEXT, Chr(1))
                bookRec.Mobiel = Mid(strTEXT, lngMaand, lngDagen - lngMaand)
                lngMaand = lngDagen + 1
                lngDagen = InStr(lngMaand, strTEXT, Chr(1))
                bookRec.Telwerk = Mid(strTEXT, lngMaand, lngDagen - lngMaand)
                lngMaand = lngDagen + 1
                lngDagen = InStr(lngMaand, strTEXT, Chr(1))
                bookRec.FaxWerk = Mid(strTEXT, lngMaand, lngDagen - lngMaand)
                lngMaand = lngDagen + 1
                lngDagen = InStr(lngMaand, strTEXT, Chr(1))
                bookRec.Email = Mid(strTEXT, lngMaand, lngDagen - lngMaand)
                lngMaand = lngDagen + 1
                lngDagen = InStr(lngMaand, strTEXT, Chr(1))
                bookRec.URL = Mid(strTEXT, lngMaand, lngDagen - lngMaand)
                lngMaand = lngDagen + 1
                lngDagen = InStr(lngMaand, strTEXT, Chr(1))
                bookRec.Notities = Mid(strTEXT, lngMaand, lngDagen - lngMaand)
                
                Print #fptr, bookRec.Displaynaam
                Print #fptr, bookRec.Achternaam
                Print #fptr, bookRec.Voorletters
                Print #fptr, bookRec.Adres1
                Print #fptr, bookRec.Adres2
                Print #fptr, bookRec.Postcode
                Print #fptr, bookRec.Plaats
                Print #fptr, bookRec.Provincie
                Print #fptr, bookRec.Land
                Print #fptr, bookRec.Telefoon
                Print #fptr, bookRec.Fax
                Print #fptr, bookRec.Mobiel
                Print #fptr, bookRec.Telwerk
                Print #fptr, bookRec.FaxWerk
                Print #fptr, bookRec.Email
                Print #fptr, bookRec.URL
                Print #fptr, Database_Encrypt(bookRec.Notities)
                'Print #fptr, strText
                Close #fptr
            End If
        Next
    End If
    INI_DeleteSetting strProgramdir & "\padd-data.ini", "BOOK", "", True, True
    
    
    'Kijk of er een oude agenda is en convert die naar de nieuwe.
    booIni = INI_GetKey("AGENDA", "ID", strProgramdir & "\padd-data.ini")
    If booIni Then
        lngMax = iniValue
        INI_WriteKey "AGENDA", "ID", CStr(iniValue), strProgramdir & "\padd\Agenda.ini"
        For lngLoop = 0 To lngMax - 1
            strIni = CStr(lngLoop + 1)
            booIni = INI_GetKey("AGENDA", strIni, strProgramdir & "\padd-data.ini")
            INI_WriteKey "AGENDA", strIni, CStr(iniValue), strProgramdir & "\padd\Agenda.ini"
        Next
    End If
    INI_DeleteSetting strProgramdir & "\padd-data.ini", "AGENDA", "", True, True
    
    'Kijk of er oude calendar items zijn en convert die naar de nieuwe.
    For lngMaand = 1 To 12
        Select Case lngMaand
            Case 1, 3, 5, 7, 8, 10, 12
                lngDagen = 31
            Case 2
                lngDagen = 29
            Case Else
                lngDagen = 30
        End Select
        booIni = INI_GetKey("CALENDAR", "mon" + Format(lngMaand, "00"), strProgramdir & strThemedir & strThemeName & ".skn")
        strMaand = iniValue
        For lngLoop = 1 To lngDagen
            strIni = Format(lngMaand, "00") & Format(lngLoop, "00")
            booIni = INI_GetKey("CALENDAR", strIni, strProgramdir & "\padd-data.ini")
            If booIni = True And iniValue <> "" Then
                INI_WriteKey "CALENDAR", strIni, CStr(iniValue), strProgramdir & "\Padd\Calendar.ini"
            End If
        Next
    Next
   INI_DeleteSetting strProgramdir & "\padd-data.ini", "CALENDAR", "", True, True
    
    'kijk of er oude logs zijn en converteer die naar de nieuwe!
    booIni = INI_GetKey("LOG", "ID", strProgramdir & "\padd-data.ini")
    frmMain.lstSorted1.Clear
    If booIni Then
        lngMax = iniValue
        For lngLoop = 0 To lngMax - 1
            strIni = CStr(lngLoop + 1)
            booIni = INI_GetKey("LOG", strIni, strProgramdir & "\padd-data.ini")
            If booIni = True Then
                frmMain.lstSorted1.AddItem Database_Decrypt(iniValue)
                frmMain.lstSorted1.ItemData(frmMain.lstSorted1.NewIndex) = lngLoop
            End If
        Next
        For lngLoop = 0 To frmMain.lstSorted1.ListCount - 1
            strIni = frmMain.lstSorted1.List(lngLoop)
            If strIni <> "" Then
                strMaand = Mid(strIni, 1, 14)
                strTEXT = Mid(strIni, 16)
                fptr = freefile
                Open strProgramdir & "\Padd\Logbook\" & strMaand & ".log" For Output As #fptr
                Print #fptr, strTEXT
                Close #fptr
            End If
        Next
        INI_DeleteSetting strProgramdir & "\padd-data.ini", "LOG", "", True, True
    End If
    
    
    'Kijk of er oude notes zijn en convert die naar de nieuwe!
    booIni = INI_GetKey("NOTES", "ID", strProgramdir & "\padd-data.ini")
    frmMain.lstSorted1.Clear
    If booIni Then
        lngMax = iniValue
        For lngLoop = 0 To lngMax - 1
            strIni = CStr(lngLoop + 1)
            booIni = INI_GetKey("NOTES", strIni, strProgramdir & "\padd-data.ini")
            If booIni = True Then
                frmMain.lstSorted1.AddItem Database_Decrypt(iniValue)
                frmMain.lstSorted1.ItemData(frmMain.lstSorted1.NewIndex) = lngLoop
            End If
        Next
        For lngLoop = 0 To frmMain.lstSorted1.ListCount - 1
            strIni = frmMain.lstSorted1.List(lngLoop)
            If strIni <> "" Then
                strTitel = Mid(strIni, 1, InStr(strIni, Chr(1)) - 1)
                strTEXT = Mid(strIni, InStr(strIni, Chr(1)) + 1)
                fptr = freefile
                Open strProgramdir & "\Padd\Notes\200201010101" & Format(lngLoop, "00") & ".not" For Output As #fptr
                Print #fptr, strTitel
                Print #fptr, strTEXT
                Close #fptr   ' Close file.
            End If
        Next
        INI_DeleteSetting strProgramdir & "\padd-data.ini", "NOTES", "", True, True
    End If
    
    'Kijk of er oude todo zijn en convert die naar de nieuwe!
    booIni = INI_GetKey("TODO", "ID", strProgramdir & "\padd-data.ini")
    frmMain.lstSorted1.Clear
    If booIni Then
        lngMax = iniValue
        For lngLoop = 0 To lngMax - 1
            strIni = CStr(lngLoop + 1)
            booIni = INI_GetKey("TODO", strIni, strProgramdir & "\padd-data.ini")
            If booIni = True Then
                frmMain.lstSorted1.AddItem Database_Decrypt(iniValue)
                frmMain.lstSorted1.ItemData(frmMain.lstSorted1.NewIndex) = lngLoop
            End If
        Next
        For lngLoop = 0 To frmMain.lstSorted1.ListCount - 1
            strIni = frmMain.lstSorted1.List(lngLoop)
            If strIni <> "" Then
                strTitel = Mid(strIni, 1, InStr(strIni, Chr(1)) - 1)
                strTEXT = Mid(strIni, InStr(strIni, Chr(1)) + 1)
                fptr = freefile
                Open strProgramdir & "\Padd\Todo\200201010101" & Format(lngLoop, "00") & ".tod" For Output As #fptr
                Print #fptr, strTitel
                Print #fptr, strTEXT
                Close #fptr   ' Close file.
            End If
        Next
        INI_DeleteSetting strProgramdir & "\padd-data.ini", "TODO", "", True, True
    End If
    
End Sub


Public Sub Padd_Load()
    Dim myLeft As Long
    Dim myTop As Long
    Dim myWidth As Long
    Dim myHeight As Long
    Dim myKomma As Long
    Dim myTemp As String

    'Nog niets te doen hhehe
    If INI_GetKey("CALENDAR", "month", strProgramdir & strThemedir & strThemeName & ".skn") = True Then
        myKomma = InStr(iniValue, ",") + 1
        myTemp = Mid(iniValue, 1, myKomma - 2)
        If (Right(myTemp, 1) = "%") Then
            myLeft = val((frmMain.ScaleWidth * val(myTemp)) / 100)
        Else
            myLeft = val(myTemp)
        End If
        myTemp = Mid(iniValue, myKomma, InStr(myKomma + 1, iniValue, ",") - myKomma)
        If (Right(myTemp, 1) = "%") Then
            myTop = val((frmMain.ScaleHeight * val(myTemp)) / 100)
        Else
            myTop = val(myTemp)
        End If
        myKomma = InStr(myKomma + 1, iniValue, ",") + 1
        myTemp = Mid(iniValue, myKomma, InStr(myKomma + 1, iniValue, ",") - myKomma)
        If (Right(myTemp, 1) = "%") Then
            myWidth = val((frmMain.ScaleWidth * val(myTemp)) / 100)
        Else
            myWidth = val(myTemp)
        End If
        myKomma = InStr(myKomma + 1, iniValue, ",") + 1
        myTemp = Mid(iniValue, myKomma)
        If (Right(myTemp, 1) = "%") Then
            myHeight = val((frmMain.ScaleHeight * val(myTemp)) / 100)
        Else
            myHeight = val(myTemp)
        End If
        If myLeft < 0 Then myLeft = frmMain.ScaleWidth + myLeft
        If myTop < 0 Then myTop = frmMain.ScaleHeight + myTop
        If myWidth <= 0 Then myWidth = frmMain.ScaleWidth + myWidth - myLeft
        If myHeight <= 0 Then myHeight = frmMain.ScaleHeight + myHeight - myTop
        frmMain.picMonth.Left = myLeft
        frmMain.picMonth.Top = myTop
        frmMain.picMonth.Width = myWidth
        frmMain.picMonth.Height = myHeight
    End If
    INI_GetKey "OVERVIEW", "textA", strProgramdir & strThemedir & strThemeName & ".skn"
    text_overviewA = iniValue
    INI_GetKey "OVERVIEW", "textB", strProgramdir & strThemedir & strThemeName & ".skn"
    text_overviewB = iniValue
    INI_GetKey "OVERVIEW", "textC", strProgramdir & strThemedir & strThemeName & ".skn"
    text_overviewC = iniValue
    
    INI_GetKey "Overview", "load", strProgramdir & strThemedir & strThemeName & ".skn"
    strOverviewClick = iniValue

End Sub

Public Sub Todo_Delete()
    Dim lngLoop As Long
    Dim strIni As String
    Dim booIni As Boolean
    
    If frmMain.txtMBox(1).Text = "" Then
        Exit Sub
    End If
    If intUndo >= 0 Then
        If (MsgBox("Are you sure to delete this item?", vbYesNo, "LCARS Terminal") = vbYes) Then
            strIni = Mid(frmMain.lstSorted1.List(intUndo), InStr(frmMain.lstSorted1.List(intUndo), Chr(1)) + 1)
            frmMain.lstSorted1.RemoveItem intUndo
            booIni = INI_GetKey("PADD", "Todo", strProgramdir & "\padd\directories.ini")
            Kill iniValue & "\" & strIni
            Todo_Init
            Todo_Load -1
            intUndo = -1
            Overview_Load
        End If
    End If
End Sub

Public Sub Todo_Done()
    Dim strIni As String
    
    strIni = "1" & Mid(frmMain.lstSorted1.List(intUndo), 2)
    frmMain.lstSorted1.List(intUndo) = strIni
    Todo_Save
End Sub

Public Sub Todo_Init()
    Dim lngLoop As Long
    Dim booIni As Boolean
    Dim strIni As String
    Dim strTitel As String
    Dim fptr
    Dim strCheck As String
    
    strCheck = Check_Shareware

    'Nieuwe normale notes inladen.
    frmMain.lstSorted1.Clear
    'frmMain.File1.Pattern = "*.tod"
    booIni = INI_GetKey("PADD", "Todo", strProgramdir & "\padd\directories.ini")
    frmMain.File1.Path = iniValue
    frmMain.File1.Refresh
    
    For lngLoop = 0 To frmMain.File1.ListCount - 1
        fptr = freefile
        Open iniValue & "\" & frmMain.File1.List(lngLoop) For Input As #fptr
        Line Input #fptr, strIni
        Line Input #fptr, strTitel
        Close #fptr
        If (strCheck = "" And lngLoop < 10) Or strCheck <> "" Then
            frmMain.lstSorted1.AddItem strIni & strTitel & Chr(1) & frmMain.File1.List(lngLoop)
            frmMain.lstSorted1.ItemData(frmMain.lstSorted1.NewIndex) = lngLoop
        End If
    Next
    
    frmMain.lstBox(2).Clear
    For lngLoop = 0 To frmMain.lstSorted1.ListCount - 1
        strIni = frmMain.lstSorted1.List(lngLoop)
        If strIni <> "" Then
            If Left(strIni, 1) = "0" Then
                strTitel = "TODO"
            Else
                strTitel = "DONE"
            End If
            frmMain.lstBox(2).AddItem strTitel & "  " & Mid(strIni, 2, InStr(strIni, Chr(1)) - 2)
            frmMain.lstBox(2).ItemData(frmMain.lstBox(2).NewIndex) = frmMain.lstSorted1.ItemData(lngLoop)
        End If
    Next
    booIni = INI_GetKey("TODO", "load", strProgramdir & strThemedir & strThemeName & ".skn")
    strLoadClick = iniValue
    intUndo = -1
End Sub

Public Sub Todo_Load(intIndex As Integer)
    Dim strIni As String
    Dim fptr
    Dim strFile As String
    Dim booIni As Boolean

    If frmMain.lstSorted1.List(intIndex) <> "" Then
        strIni = frmMain.lstSorted1.List(intIndex)
        If Left(strIni, 1) = "0" Then
            frmMain.imgBut(buttonDone).Visible = True
        Else
            frmMain.imgBut(buttonDone).Visible = False
        End If
        strFile = Mid(strIni, InStr(strIni, Chr(1)) + 1)
        fptr = freefile
        booIni = INI_GetKey("PADD", "Todo", strProgramdir & "\padd\directories.ini")
        Open iniValue & "\" & strFile For Input As #fptr
        Line Input #fptr, strFile
        frmMain.txtMBox(1).Text = ""
        While Not EOF(fptr)
            Line Input #fptr, strFile
            frmMain.txtMBox(1).Text = frmMain.txtMBox(1).Text & strFile & vbCrLf
        Wend
        Close #fptr
    Else
        frmMain.imgBut(buttonDone).Visible = False
        frmMain.txtMBox(1).Text = ""
    End If
End Sub

Public Sub Todo_Save()
    Dim strTemp As String
    Dim lngLoop As Long
    Dim strIni As String
    Dim strFile As String
    Dim booIni As Boolean
    Dim fptr
    
    If Check_Shareware = "" Then
        MsgBox RegisterText, vbInformation, "LCARS Terminal"
    End If

    If intUndo >= 0 Then
        strFile = Mid(frmMain.lstSorted1.List(intUndo), InStr(frmMain.lstSorted1.List(intUndo), Chr(1)) + 1)
        strTemp = Mid(frmMain.lstSorted1.List(intUndo), 1, 1)
    Else
        strFile = Format(Now, "yyyymmddHhNnSs") & ".tod"
        strTemp = "0"
    End If
    fptr = freefile
    booIni = INI_GetKey("PADD", "Todo", strProgramdir & "\padd\directories.ini")
    Open iniValue & "\" & strFile For Output As #fptr
    Print #fptr, strTemp
    strTemp = frmMain.txtMBox(1).Text
    If strTemp = "" Then frmMain.txtMBox(1).Text = "---"
    Print #fptr, frmMain.txtMBox(1).Text
    Close #fptr
    Todo_Init
    Todo_Load -1
    intUndo = -1
    Overview_Load
End Sub

Public Function WSystemDirectory() As String
    ' Retrieve the system directory.
    Dim strBuffer As String
    Dim lngLen As Long
    
    strBuffer = Space(MaxPath)
    lngLen = MaxPath
    
    lngLen = GetSystemDirectory(strBuffer, lngLen)
    ' If the path is longer than dhcMaxPath, then
    ' lngLen contains the correct length. Resize the
    ' buffer and try again.
    If lngLen > MaxPath Then
        strBuffer = Space(lngLen)
        lngLen = GetSystemDirectory(strBuffer, lngLen)
    End If
    WSystemDirectory = Left$(strBuffer, lngLen)
End Function
