Jump to content

Recommended Posts

Posted

Hi

I found a post with a very nice Reminder https://www.autoitscript.com/forum/topic/39015-reminder-alert/ but the code was old and Functions have changed.

I have very little experience of using these listview funnctions

I tried to adjust to the new function calls and manage to make it run

_ReminderProg ()

Func _ReminderProg ()
#include <GUIConstants.au3>
#Include <GuiListView.au3>
#include <String.au3>

Opt("TrayMenuMode",1)
Global $mainReminder
GuiCreate("Reminder", 600, 500, -1, -1)
GUISetBkColor (0x6BC072)
    $mainReminder = GuiCtrlCreateListview("", 5, 5, 590, 445, $LVS_SHOWSELALWAYS)
        GUICtrlSetBkColor(-1,0xA6D9AA)
        _GUICtrlListView_InsertColumn($mainReminder, 0, "Event", 316)
        _GUICtrlListView_InsertColumn($mainReminder, 1, "Time", 100)
        _GUICtrlListView_InsertColumn($mainReminder, 2, "Date", 100)
    $addreminder = GuiCtrlCreateButton("Add a new reminder", 15, 460, 230, 30)
    $deletereminder = GuiCtrlCreateButton("Delete selected reminders", 260, 460, 230, 30)
    $exit = GuiCtrlCreateButton("Exit", 505, 460, 80, 30)

    $addReminderItem = TrayCreateItem("Add reminder")
        TrayCreateItem('')
    $show = TrayCreateItem("Open Reminder...")
    $exitItem = TrayCreateItem("Exit")

$pastinfo = InireadSectionNames(@ScriptDir & "\reminderinfo.ini")
If IsArray($pastInfo) then
    For $a = 1 to $pastInfo[0]
        $info = InireadSection(@ScriptDir & "\reminderinfo.ini", $pastinfo[$a])
        If IsArray($info) and $info[0][0] <> 0 then
            For $b = 1 to $info[0][0]
                $temp = StringSplit($info[$b][1], ":")
                $pos = _InsertOrder($info[$b][0], $temp[1], $temp[2])
                _GUICtrlListView_InsertItem ($mainReminder, $pastinfo[$a] & "|" & $info[$b][1] & "|" & $info[$b][0], $pos)
            Next
        Endif
    Next
Endif

GUIsetstate()

While 1
    $msg = GuiGetMsg()
    $trayMsg = TrayGetMsg()
    Select
        Case $msg = $exit
            Exit
        Case $msg = $deleteReminder
            _DeleteReminder()
        Case $msg = $GUI_EVENT_CLOSE
            WinSetState('Reminder', '', @SW_HIDE)
        Case $trayMsg = $exitItem
            Exit
        Case $trayMsg = $addreminderItem or $msg = $addReminder
            _AddReminder()
        Case $trayMsg = $show
            WinSetState('Reminder', '', @SW_SHOW)
        Case Else
            If _GUICtrlListView_GetItemCount($mainReminder) > 0 Then
                $splitInfo = Stringsplit(_GUICtrlListView_GetItemText($mainReminder, 0), "|")
                $splitDate = Stringsplit($splitInfo[3], "/")
                $splitTime = Stringsplit($splitInfo[2], ":")
                If Number($splitDate[3]) <= @YEAR and Number($splitDate[1]) <= @MON and Number($splitDate[2]) <= @MDAY and Number($splitTime[1]) <= @Hour and Number($splitTime[2]) <= @MIN then
                    Msgbox(0, "Reminder alert", $splitInfo[1])
                    Inidelete(@ScriptDir & "\reminderinfo.ini", $splitInfo[1])
                    _GUICtrlListView_DeleteItem($mainReminder, 0)
                Endif
            Endif
    EndSelect
Wend
EndFunc

Func _Addreminder()
    $gui = GuiCreate("Add a reminder", 200, 280)
    GuiCtrlCreateLabel("Reminder Name", 10, 5, 180, 25, $ES_center)
    $name = GuiCtrlCreateInput("", 10, 25, 180, 20)
    $date = GUICtrlCreateMonthCal(@YEAR & "/" & @MON & "/" & @MDAY, 10, 55, 180, 160, $MCS_NOTODAY)
    GuiCtrlCreateLabel("Hour:", 5, 223, 30, 25, $SS_RIGHT)
    $hour = GuiCtrlCreateCombo("", 40, 220, 40, 25)
    GuiCtrlSetData(-1, "0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23")
    GuiCtrlCreateLabel("Minute:", 100, 223, 35, 25, $SS_RIGHT)
    $minute = GuiCtrlCreateCombo("", 140, 220, 40, 25)
    GuiCtrlSetData(-1, "0|5|10|15|20|25|30|35|40|45|50|55")
    $ok = GuiCtrlCreateButton("Add Reminder", 10, 250, 180, 25)
    Guisetstate(@SW_SHOW)

    While 1
        $ms = GuiGetMsg()
        If $ms = $GUI_EVENT_CLOSE then
            GuiDelete($gui)
            Return
        Endif
        If Bitand($ms = $ok, GuiCtrlRead($name) <> "", GuiCtrlRead($hour) <> "", GuiCtrlRead($minute) <> "") Then
            $date = Stringsplit(GuiCtrlRead($date), "/")
            If $date[2] < 10 then $date[2] = StringTrimLeft($date[2], 1)
            If $date[3] < 10 then $date[3] = StringTrimLeft($date[3], 1)
;~             $date = $date[2] & "/" & $date[3] & "/" & $date [1]
            $date = $date[3] & "/" & $date[2] & "/" & $date [1]
            $hour = GuiCtrlRead($hour)
            $minute = GuiCtrlRead($minute)
            If StringLen($minute) < 2 then
                $minute = _StringInsert($minute, "0", 0)
            Endif
            $pos = _InsertOrder($date, $hour, $minute)
            $time =  $hour & ":" & $minute
            _GUICtrlListView_InsertItem ($mainReminder, GuiCtrlRead($name) & "|" & $time & "|" & $date, $pos)
            If StringLen($hour) < 2 then _StringInsert($hour, "0", 0)
            Iniwrite(@ScriptDir & "\reminderinfo.ini", GuiCtrlRead($name), $date, $time)
            GuiDelete($gui)
            ExitLoop
        EndIf
    Wend
EndFunc

Func _DeleteReminder()
    $selected = _GUICtrlListView_GetSelectedIndices($mainReminder, 1)
    If $selected <> -1 then
        If IsArray($selected) then
            For $a = 1 to $selected[0]
                $temp = _GUICtrlListView_GetItemTextArray ($mainReminder, $selected[$a])
                Inidelete(@ScriptDir & "\reminderinfo.ini", $temp[1], $temp[3])
                Inidelete(@ScriptDir & "\reminderinfo.ini", $temp[1])
            Next
        Else
            $temp = _GUICtrlListView_GetItemTextArray ($mainReminder, $selected)
            Inidelete(@ScriptDir & "\reminderinfo.ini", $temp[1], $temp[3])
            Inidelete(@ScriptDir & "\reminderinfo.ini", $temp[1])
        Endif
        _GUICtrlListView_DeleteItemsSelected ($mainReminder)
    Endif
Endfunc

Func _InsertOrder($date, $hour, $minute)
    $temp = StringSplit($date, "/")
    Dim $checkInfo[5] = [Int($temp[3]), Int($temp[1]),Int($temp[2]),Int($hour),Int($minute)]
    If _GUICtrlListView_GetItemCount($mainReminder) = 0 then Return -1
    For $a = 0 to _GUICtrlListView_GetItemCount($mainReminder)
        $temp = _GUICtrlListView_GetItemTextArray ($mainReminder, $a)
        If IsArray($temp) then
            $listDate = StringSplit($temp[3], "/")
            $listTime = StringSplit($temp[2], ":")
            Dim $listInfo[5] = [Int($listDate[3]),Int($listDate[1]),Int($listDate[2]),Int($listTime[1]),Int($listTime[2])]
            For $b = 1 to 5
                If $checkInfo[$b] < $listInfo[$b] then Return $a
                If $checkInfo[$b] > $listInfo[$b] then $b += 5
                Next
        Else
            Return -1
        Endif
    Next
Endfunc

However it will insert and delete one reminder and then it crashes.

I suspect that a nested listview should be used somewhere instead of a simple one but I dont know how it can be done.

If done this program would be very usefull.

Can anyone help?

Posted (edited)

The link in your post is broken, but i found the thread: 

the listview udf has many script breaking changes since 2007.

Quote

 

I think to write a new script is better and will make a relaunch of this idea soon. The script (origin with some MsgBox and arrayDisplays):

#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <String.au3>

Opt("TrayMenuMode", 1)

GUICreate("Reminder", 600, 500, -1, -1)
GUISetBkColor(0x6BC072)
$main = GUICtrlCreateListView("", 5, 5, 590, 445, $LVS_SHOWSELALWAYS)
GUICtrlSetBkColor(-1, 0xA6D9AA)
_GUICtrlListView_InsertColumn($main, 0, "Event", "", 316)
_GUICtrlListView_InsertColumn($main, 1, "Time", "", 100)
_GUICtrlListView_InsertColumn($main, 2, "Date", "", 100)
$addreminder = GUICtrlCreateButton("Add a new reminder", 15, 460, 230, 30)
$deletereminder = GUICtrlCreateButton("Delete selected reminders", 260, 460, 230, 30)
$exit = GUICtrlCreateButton("Exit", 505, 460, 80, 30)

$addReminderItem = TrayCreateItem("Add reminder")
TrayCreateItem('')
$show = TrayCreateItem("Open Reminder...")
$exitItem = TrayCreateItem("Exit")

$aPastinfo = IniReadSectionNames(@ScriptDir & "\reminderinfo.ini")
If IsArray($aPastinfo) Then
    For $a = 1 To $aPastinfo[0]
        $info = IniReadSection(@ScriptDir & "\reminderinfo.ini", $aPastinfo[$a])
        If IsArray($info) And $info[0][0] <> 0 Then
            For $b = 1 To $info[0][0]
                $temp = StringSplit($info[$b][1], ":")
                $pos = _InsertOrder($info[$b][0], $temp[1], $temp[2])
                _GUICtrlListView_InsertItem($main, $pos, $aPastinfo[$a] & "|" & $info[$b][1] & "|" & $info[$b][0])
            Next
        EndIf
    Next
EndIf

GUISetState()

While 1
    $msg = GUIGetMsg()
    $trayMsg = TrayGetMsg()
    Select
        Case $msg = $exit
            Exit
        Case $msg = $deletereminder
            _DeleteReminder()
        Case $msg = $GUI_EVENT_CLOSE
            WinSetState('Reminder', '', @SW_HIDE)
        Case $trayMsg = $exitItem
            Exit
        Case $trayMsg = $addReminderItem Or $msg = $addreminder
            _Addreminder()
        Case $trayMsg = $show
            WinSetState('Reminder', '', @SW_SHOW)
        Case Else
            If _GUICtrlListView_GetItemCount($main) > 0 Then
                $aSplitInfo = _GUICtrlListView_GetItemTextArray($main, 0)
                ;========================
                ;_ArrayDisplay($aSplitInfo)
                If $aSplitInfo[2] <> '' And $aSplitInfo[3] <> '' Then
                    $splitDate = StringSplit($aSplitInfo[3], "/")
                    $splitTime = StringSplit($aSplitInfo[2], ":")
                    If Number($splitDate[3]) <= @YEAR And Number($splitDate[1]) <= @MON And Number($splitDate[2]) <= @MDAY And Number($splitTime[1]) <= @HOUR And Number($splitTime[2]) <= @MIN Then
                        MsgBox(0, "Reminder alert", $aSplitInfo[1])
                        IniDelete(@ScriptDir & "\reminderinfo.ini", $aSplitInfo[1])
                        _GUICtrlListView_DeleteItem($main, 0)
                    EndIf
                EndIf
            EndIf
    EndSelect
WEnd

Func _Addreminder()
    $gui = GUICreate("Add a reminder", 200, 280)
    GUICtrlCreateLabel("Reminder Name", 10, 5, 180, 25, $ES_center)
    $name = GUICtrlCreateInput("", 10, 25, 180, 20)
    $date = GUICtrlCreateMonthCal(@YEAR & "/" & @MON & "/" & @MDAY, 10, 55, 180, 160, $MCS_NOTODAY)
    GUICtrlCreateLabel("Hour:", 5, 223, 30, 25, $SS_RIGHT)
    $hour = GUICtrlCreateCombo("", 40, 220, 40, 25)
    GUICtrlSetData(-1, "0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23")
    GUICtrlCreateLabel("Minute:", 100, 223, 35, 25, $SS_RIGHT)
    $minute = GUICtrlCreateCombo("", 140, 220, 40, 25)
    GUICtrlSetData(-1, "0|5|10|15|20|25|30|35|40|45|50|55")
    $ok = GUICtrlCreateButton("Add Reminder", 10, 250, 180, 25)
    GUISetState(@SW_SHOW)

    While 1
        $ms = GUIGetMsg()
        If $ms = $GUI_EVENT_CLOSE Then
            GUIDelete($gui)
            Return
        EndIf
        If BitAND($ms = $ok, GUICtrlRead($name) <> "", GUICtrlRead($hour) <> "", GUICtrlRead($minute) <> "") Then
            MsgBox(64, 'm. BitAnd','work',5,$gui)
            $date = StringSplit(GUICtrlRead($date), "/")
            If $date[2] < 10 Then $date[2] = StringTrimLeft($date[2], 1)
            If $date[3] < 10 Then $date[3] = StringTrimLeft($date[3], 1)
            $date = $date[2] & "/" & $date[3] & "/" & $date[1]
            $hour = GUICtrlRead($hour)
            $minute = GUICtrlRead($minute)
            If StringLen($minute) < 2 Then
                $minute = _StringInsert($minute, "0", 0)
            EndIf
            $pos = _InsertOrder($date, $hour, $minute)
            $time = $hour & ":" & $minute
            _GUICtrlListView_InsertItem($main, $pos, GUICtrlRead($name) & "|" & $time & "|" & $date)
            If StringLen($hour) < 2 Then _StringInsert($hour, "0", 0)
            IniWrite(@ScriptDir & "\reminderinfo.ini", GUICtrlRead($name), $date, $time)
            GUIDelete($gui)
            ExitLoop
        Else
            MsgBox(64, 'm. BitAnd',"didn't work",5,$gui)
        EndIf

    WEnd
EndFunc   ;==>_Addreminder

Func _DeleteReminder()
    $selected = _GUICtrlListView_GetSelectedIndices($main, 1)
    If $selected <> -1 Then
        If IsArray($selected) Then
            For $a = 1 To $selected[0]
                $temp = _GUICtrlListView_GetItemTextArray($main, $selected[$a])
                IniDelete(@ScriptDir & "\reminderinfo.ini", $temp[1], $temp[3])
                IniDelete(@ScriptDir & "\reminderinfo.ini", $temp[1])
            Next
        Else
            $temp = _GUICtrlListView_GetItemTextArray($main, $selected)
            IniDelete(@ScriptDir & "\reminderinfo.ini", $temp[1], $temp[3])
            IniDelete(@ScriptDir & "\reminderinfo.ini", $temp[1])
        EndIf
        _GUICtrlListView_DeleteItemsSelected($main)
    EndIf
EndFunc   ;==>_DeleteReminder

Func _InsertOrder($date, $hour, $minute)
    ConsoleWrite($date & ' ' & $hour & ':' & $minute & @CRLF)
    $temp = StringSplit($date, "/")
    Dim $aCheckInfo[5] = [Int($temp[3]), Int($temp[1]), Int($temp[2]), Int($hour), Int($minute)]
;   _ArrayDisplay($aCheckInfo, 'CheckInfo line 135')
    If _GUICtrlListView_GetItemCount($main) = 0 Then Return -1
    #cs
    For $a = 0 To _GUICtrlListView_GetItemCount($main)
        $temp = _GUICtrlListView_GetItemTextArray($main, $a)
        _ArrayDisplay($aCheckInfo, 'temp line 139')
        If IsArray($temp) Then
            $listDate = StringSplit($temp[3], "/")
            $listTime = StringSplit($temp[2], ":")
            Dim $listInfo[5] = [Int($listDate[3]), Int($listDate[1]), Int($listDate[2]), Int($listTime[1]), Int($listTime[2])]
            For $b = 1 To 5
                If $aCheckInfo[$b] < $listInfo[$b] Then Return $a
                If $aCheckInfo[$b] > $listInfo[$b] Then $b += 5
            Next
        Else
            Return -1
        EndIf
    Next
    #ce
EndFunc   ;==>_InsertOrder

 

Edited by AutoBert
Posted

thanks Autobert.

It would be nice if it worked

I will try to examine the code every once in a while and try to figure it out

But I am starting to wonder wether the initial code really worked.

Posted (edited)
22 hours ago, hawkair said:

But I am starting to wonder wether the initial code really worked.

Maybe 2007.

Here is a rewrited HOT Version:

#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_LegalCopyright=autoBert
#AutoIt3Wrapper_Res_Language=1031
#AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4
#AutoIt3Wrapper_Run_Tidy=y
#AutoIt3Wrapper_Run_Au3Stripper=n
#Au3Stripper_Parameters=/mo

#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <String.au3>
#include <Date.au3>
#include <File.au3>

#cs
    Nice to have (when it's done):
        Change Txt-File saving to SQLite based saving
        Split in 2 Apps: 1 for Add Data
                         1 for Alarm from Reminder
    What's to do:
        Implement checking of DateTime for alarm
        Testing (maybe enhance)
#ce

Opt('GUIOnEventMode', 1)
Global Const $sLV_SavePath = @ScriptDir & '\Reminder.LV.txt'
Global $hMain = GUICreate("Reminder", 600, 500, -1, -1), $hRem
GUISetBkColor(0x6BC072)
Global $idLV = GUICtrlCreateListView("Event|Date+Time|Repeated|Interval", 5, 5, 590, 445, BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT), BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
GUICtrlSetBkColor(-1, 0xA6D9AA)
GUICtrlSetOnEvent($idLV, '_SortByCol')

_GUICtrlListView_SetColumnWidth($idLV, 0, 256)
_GUICtrlListView_SetColumnWidth($idLV, 1, 140)
_GUICtrlListView_SetColumnWidth($idLV, 2, 80)
_GUICtrlListView_SetColumnWidth($idLV, 3, 70)

Global $idAdd = GUICtrlCreateButton("&Add a new reminder", 15, 460, 230, 30)
Global $idDelete = GUICtrlCreateButton("&Delete selected reminders", 260, 460, 230, 30)
Global $idExit = GUICtrlCreateButton("E&xit", 505, 460, 80, 30)

GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit')
GUICtrlSetOnEvent($idDelete, '_Delete')
GUICtrlSetOnEvent($idAdd, '_Add')
GUICtrlSetOnEvent($idExit, '_Exit')

_GUICtrlListView_RegisterSortCallBack($idLV) ; damit man das Listview (mit Klick auf die Spaltenüberschrift) sortieren kann
_GUICtrlListView_SortItems($idLV, 1)     ; Einträge entsprechend sortieren
_ReadLV()
GUISetState()
AdlibRegister('_CheckRemind', 15000)

;$addReminderItem = TrayCreateItem("Add reminder")
;TrayCreateItem('')
;$show = TrayCreateItem("Open Reminder...")
;$exitItem = TrayCreateItem("Exit")
While 1
    Sleep(10000)
WEnd

Func _CheckRemind()
    Local $sQuest, $sFlag, $iRet, $aDate, $aTime, $dtNewDate
    Local $aRemind = _GUICtrlListView_GetItemTextArray($idLV, 0) ;Item 0 allways oldest in remindeing-queue
    _DateTimeSplit($aRemind[2], $aDate, $aTime)
    $sQuest = 'is reached!' & @CRLF
    If $aRemind[3] <> 'no' Then
        $sQuest = 'Move for ' & $aRemind[4] & StringTrimRight($aRemind[3], 2) & '?'
        $sFlag = BitOR($MB_ICONINFORMATION, $MB_YESNO)
    Else
        $sFlag = BitOR($MB_ICONINFORMATION, $MB_OK)
    EndIf
    ;_ArrayDisplay($aRemind)
    Local $dtNow = @YEAR & '/' & @MON & '/' & @MDAY & ' ' & StringRight('00' & @HOUR, 2) & ':' & StringRight('00' & @MIN, 2)
    ConsoleWrite('line 74: ' & $dtNow & ' < ' & $aRemind[2] & ' Return? ' & ($dtNow < $aRemind[2]) & @CRLF)
    If $dtNow < $aRemind[2] Then Return
    $iRet = MsgBox($sFlag, $aRemind[1] & $aRemind[2], $sQuest, 0, $hMain)
    If $aRemind[3] <> 'no' Then
        If $iRet <> $IDNO Then
            $dtNewDate = _DateAdd(StringLeft($aRemind[3], 1), $aRemind[4], $aDate[1] & '/' & $aDate[2] & '/' & $aDate[3] & ' ' & $aTime[1] & ':' & $aTime[2])
            GUICtrlCreateListViewItem($aRemind[1] & "|" & $dtNewDate & '|' & $aRemind[3] & '|' & $aRemind[4], $idLV)
        EndIf
    EndIf
    If $iRet <> $IDNO Then _GUICtrlListView_DeleteItem($idLV, 0)
    ;to be checked
EndFunc   ;==>_CheckRemind

Func _ReadLV()
    Local $aLV, $sLV_Item
    _FileReadToArray($sLV_SavePath, $aLV, $FRTA_NOCOUNT, '|')
    _ArraySort($aLV, 0, 0, 0, 1)
    ;_ArrayDisplay($aLV)
    For $i = 0 To UBound($aLV) - 1
        $sLV_Item = ''
        For $j = 0 To 3
            $sLV_Item &= $aLV[$i][$j] & '|'
        Next
        $sLV_Item = StringTrimRight($sLV_Item, 1)
        GUICtrlCreateListViewItem($sLV_Item, $idLV)
    Next
EndFunc   ;==>_ReadLV

Func _exit()
    Local $sLV_AllItems, $hFile
    For $i = 0 To _GUICtrlListView_GetItemCount($idLV) - 1
        $sLV_AllItems &= _GUICtrlListView_GetItemTextString($idLV, $i) & @CRLF
    Next
    $sLV_AllItems = StringTrimRight($sLV_AllItems, 2)
    ;   MsgBox(0, '', $sLV_AllItems)
    FileMove($sLV_SavePath, StringReplace($sLV_SavePath, '.txt', '.bak'), $FC_OVERWRITE)
    $hFile = FileOpen($sLV_SavePath, $FO_OVERWRITE)
    FileWrite($hFile, $sLV_AllItems)
    FileClose($hFile)
    Exit
EndFunc   ;==>_exit

Func _SortByCol()
    _GUICtrlListView_SortItems($idLV, GUICtrlGetState($idLV)) ; Einträge entsprechend sortieren
EndFunc   ;==>_SortByCol

Func _Add()
    Opt('GUIOnEventMode', 0)
    Local $msg, $sRep = 'dayly|weekly|monthly|yearly', $dtEvenDate, $iHour, $iMinute, $iTime, $iVal
    $hRem = GUICreate("Add a reminder", 200, 320, -1, -1, Default, Default, $hMain)
    GUICtrlCreateLabel("Reminder Name", 10, 5, 180, 25, $ES_center)
    Local $idInpEvent = GUICtrlCreateInput("", 10, 25, 180, 20)
    Local $idDate = GUICtrlCreateMonthCal(@YEAR & "/" & @MON & "/" & @MDAY, 10, 55, 180, 160, $MCS_NOTODAY)
    GUICtrlCreateLabel("&Hour:", 5, 223, 30, 25, $SS_RIGHT)
    Local $idCboHour = GUICtrlCreateCombo("", 40, 220, 40, 25)
    GUICtrlSetData($idCboHour, "00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23")
    GUICtrlCreateLabel("&Minute:", 100, 223, 35, 25, $SS_RIGHT)
    Local $idCboMinute = GUICtrlCreateCombo("", 140, 220, 40, 25)
    GUICtrlSetData($idCboMinute, "00|05|10|15|20|25|30|35|40|45|50|55")
    GUICtrlCreateLabel("&Repeat:", 5, 253, 43, 25, $SS_RIGHT)
    Local $idCboRepeat = GUICtrlCreateCombo("", 60, 250, 60, 25)
    GUICtrlSetData($idCboRepeat, "no|dayly|weekly|Monthly|Yearly", "no")
    Local $idVal = GUICtrlCreateEdit('', 150, 250, 50, 25, $ES_Number)
    Local $idBtnOK = GUICtrlCreateButton("&Save Reminder", 10, 280, 180, 25)
    GUISetState(@SW_SHOW)

    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $idBtnOK
                $dtEvenDate = GUICtrlRead($idDate)
                $iHour = '00' & GUICtrlRead($idCboHour)
                $iMinute = '00' & GUICtrlRead($idCboMinute)
                $iTime = StringRight($iHour, 2) & ":" & StringRight($iMinute, 2)
                $sRep = GUICtrlRead($idCboRepeat)
                $iVal = GUICtrlRead($idVal)
                GUICtrlCreateListViewItem(GUICtrlRead($idInpEvent) & "|" & $dtEvenDate & ' ' & $iTime & '|' & $sRep & '|' & $iVal, $idLV)
                GUIDelete($hRem)
                ExitLoop
            Case $GUI_EVENT_CLOSE
                GUIDelete($hRem)
                ExitLoop
        EndSwitch
    WEnd
    GUISetState(BitOR(@SW_ENABLE, @SW_SHOW), $hMain)
    Opt('GUIOnEventMode', 1)
    ConsoleWrite(Opt('GUIOnEventMode') & @CRLF)
EndFunc   ;==>_Add

Func _Delete()
    #cs
        must be checked
    #ce
    Local $aLV_Selected = _GUICtrlListView_GetSelectedIndices($idLV, True)
    _ArrayDisplay($aLV_Selected)
    Local $sQuest
    For $i = 1 To $aLV_Selected[0]
        $sQuest &= _GUICtrlListView_GetItemTextString($idLV, $aLV_Selected[$i])
        If $i <> $aLV_Selected[0] Then $sQuest &= @CRLF
    Next
    Local $iRet = MsgBox(BitOR($MB_YESNO, $MB_ICONQUESTION), 'Delete ' & $aLV_Selected[0] & ' selected Items', $sQuest, 5, $hMain)
    If $iRet <> $IDNO Then _GUICtrlListView_DeleteItemsSelected($idLV)
EndFunc   ;==>_Delete

*) Hot means: most func's must be tested. But first check the concept.

mfg (auto)Bert

Edited by AutoBert
Posted (edited)
On 11/14/2022 at 9:21 PM, hawkair said:

You added a repeat function too!

and therefor i needed some tests. After testing i changed/added some scriptlines, this is my newest version:

#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_LegalCopyright=autoBert
#AutoIt3Wrapper_Res_Language=1031
#AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4
#AutoIt3Wrapper_Run_Tidy=y
#AutoIt3Wrapper_Run_Au3Stripper=n
#Au3Stripper_Parameters=/mo

#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <String.au3>
#include <Date.au3>
#include <File.au3>

#cs
    Nice to have (when it's done):
        Change Txt-File saving to SQLite based saving
        Split in 2 Apps: 1 for Add Data
                         1 for Alarm from Reminder
    What's to do:
        Implement checking of DateTime for alarm
        Testing (maybe enhance)
#ce

Opt('GUIOnEventMode', 1)
Global $g_bSortSense = False
Global Const $sLV_SavePath = @ScriptDir & '\Reminder.LV.txt'
;Global $iMax = 0 ; wait for user all other
Global $iMax = 15 ; sec timeout
Global $hMain = GUICreate("Reminder", 600, 500, -1, -1), $hRem
GUISetBkColor(0x6BC072)
Global $idLV = GUICtrlCreateListView("Event|Date+Time|Repeated|Interval|Birthdate|PreWarn|HiddenSort", 5, 5, 590, 445, BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT), BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
GUICtrlSetBkColor(-1, 0xA6D9AA)
GUICtrlSetOnEvent($idLV, '_SortByCol')
_GUICtrlListView_SetColumnWidth($idLV, 0, 200)
_GUICtrlListView_SetColumnWidth($idLV, 1, 140)
_GUICtrlListView_SetColumnWidth($idLV, 2, 80)
_GUICtrlListView_SetColumnWidth($idLV, 3, 70)
_GUICtrlListView_SetColumnWidth($idLV, 4, 36)
_GUICtrlListView_SetColumnWidth($idLV, 5, 70)
_GUICtrlListView_HideColumn($idLV, 6)

Global $idAdd = GUICtrlCreateButton("&Add a new reminder", 15, 460, 230, 30)
Global $idDelete = GUICtrlCreateButton("&Delete selected reminders", 260, 460, 230, 30)
Global $idExit = GUICtrlCreateButton("E&xit", 505, 460, 80, 30)

GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit')
GUICtrlSetOnEvent($idDelete, '_Delete')
GUICtrlSetOnEvent($idAdd, '_Add')
GUICtrlSetOnEvent($idExit, '_Exit')
_GUICtrlListView_RegisterSortCallBack($idLV) ; damit man das Listview (mit Klick auf die Spaltenüberschrift) sortieren kann
_GUICtrlListView_SortItems($idLV, 6)     ; Einträge entsprechend sortieren
_ReadLV()
GUISetState()
_CheckRemind()

While 1
    Sleep(10000)
WEnd

Func _CheckRemind()
    Local $sQuest, $sFlag, $iRet, $iDiff, $aDate, $aTime, $dtNewDate, $dtHidSort, $sTitle
    Local $aRemind = _GUICtrlListView_GetItemTextArray($idLV, 0) ;Item 0 allways oldest in remindeing-queue
    _DateTimeSplit($aRemind[2], $aDate, $aTime)
    $sQuest &= 'is reached!' & @CRLF
    If $aRemind[3] <> 'no' Then
        $sTitle &= $aRemind[1]
        $sQuest &= 'Move for ' & $aRemind[4] & ' * ' & StringTrimRight($aRemind[3], 2) & '(s) ?'
        $sFlag = BitOR($MB_ICONINFORMATION, $MB_YESNO)
    Else
        $sFlag = BitOR($MB_ICONINFORMATION, $MB_OK)
    EndIf
    ;_ArrayDisplay($aRemind, 'Line 73')
    Local $dtNow = @YEAR & '/' & @MON & '/' & @MDAY & ' ' & StringRight('00' & @HOUR, 2) & ':' & StringRight('00' & @MIN, 2)
    ConsoleWrite('line 75: ' & $dtNow & ' < ' & $aRemind[7] & ' Return? ' & ($dtNow < $aRemind[2]) & @CRLF)
    If $dtNow < $aRemind[7] Then AdlibRegister('_CheckRemind', 15000)
    If $dtNow < $aRemind[7] Then Return
    AdlibUnRegister('_CheckRemind')
    _GUICtrlListView_BeginUpdate($idLV)
    $iDiff = _DateDiff('d', $dtNow, $aRemind[7])
    ConsoleWrite('DtDiff: ' & $iDiff & @CRLF)
    ;   Exit
    If $aRemind[6] <> "" And $iDiff < 0 And $iDiff >= $aRemind[6] * -1 Then
        $dtHidSort = StringTrimRight(_DateAdd('h', 4, $dtNow), 2) & '00'
        If $dtHidSort < $aRemind[2] Then
            ConsoleWrite($aRemind[2] & '|' & $dtNow & @CRLF)
            $sTitle = 'Pre Warning (snooze)'
            $sFlag = BitOR($MB_ICONINFORMATION, $MB_OK)
            $sQuest = 'Will be moved to  ' & $dtHidSort & '!'
            ;MsgBox(0, 'Debug wait', '')
        EndIf
    Else
        $sTitle &= $aRemind[1]
        $sQuest = 'Move for ' & $aRemind[4] & ' * ' & StringTrimRight($aRemind[3], 2) & '(s) ?'
    EndIf
    $iRet = MsgBox($sFlag, $sTitle & ' ' & $aRemind[2], $sQuest, $iMax, $hMain)
    If $aRemind[3] <> 'no' Then
        If $iRet <> $IDNO Then
            If $sTitle = 'Pre Warning (snooze)' Then
                ConsoleWrite($aRemind[7] & '=>' & $dtHidSort & @CRLF)
                _GUICtrlListView_SetItemText($idLV, 0, $dtHidSort, 6)
            Else
                $dtNewDate = _DateAdd(StringLeft($aRemind[3], 1), $aRemind[4], $aDate[1] & '/' & $aDate[2] & '/' & $aDate[3] & ' ' & $aTime[1] & ':' & $aTime[2])
                ConsoleWrite($aRemind[2] & '=>' & $dtNewDate & @CRLF)
                _GUICtrlListView_SetItemText($idLV, 0, $dtNewDate, 1)
                $dtHidSort = _DateAdd('d', $aRemind[6] * -1, $dtNewDate)
                ConsoleWrite($aRemind[7] & '=>' & $dtHidSort & @CRLF)
                _GUICtrlListView_SetItemText($idLV, 0, $dtHidSort, 6)
                ;$aRemind = _GUICtrlListView_GetItemTextArray($idLV, 0) ;Item 0 allways oldest in remindeing-queue
                ;_ArrayDisplay($aRemind, 'line 107')
            EndIf
        EndIf
    Else
        If $iRet <> $IDNO Then _GUICtrlListView_DeleteItem($idLV, 0)
    EndIf
    _GUICtrlListView_SimpleSort($idLV, $g_bSortSense, 6, False) ; Prevent sort direction toggling for next insertion
    _GUICtrlListView_EndUpdate($idLV)
    _SaveLV()
    AdlibRegister('_CheckRemind')
    ;to be checked
EndFunc   ;==>_CheckRemind

Func _ReadLV()
    Local $aLV, $sLV_Item, $iCols, $sQuest, $sFlag, $sTitle = 'incompatible Data?', $iRet
    _FileReadToArray($sLV_SavePath, $aLV, $FRTA_NOCOUNT, '|')
    $iCols = _GUICtrlListView_GetColumnCount($idLV)
    ConsoleWrite($iCols & '|' & UBound($aLV, 2) & @CRLF)
    If $iCols <> UBound($aLV, 2) Then ;Return
        $sQuest = 'App has ' & $iCols & ' Cols, but DataFile has ' & UBound($aLV, 2) & ' Cols.' & @CRLF & @CRLF
        $sQuest &= 'Continue anyway?'
        $sFlag = BitOR($MB_ICONINFORMATION, $MB_YESNO)
        $iRet = MsgBox($sFlag, $sTitle, $sQuest, $iMax, $hMain)
        If $iRet <> $IDYES Then Exit
    EndIf
    _ArraySort($aLV, 0, 0, 0, 6)
    _GUICtrlListView_DeleteAllItems($idLV)
    ;_ArrayDisplay($aLV, 'Line 134 ')
    If UBound($aLV, 2) < $iCols Then $iCols = UBound($aLV, 2)
    For $i = 0 To UBound($aLV, 1) - 1
        $sLV_Item = ''
        For $j = 0 To $iCols - 1
            $sLV_Item &= $aLV[$i][$j] & '|'
        Next
        $sLV_Item = StringTrimRight($sLV_Item, 1)
        GUICtrlCreateListViewItem($sLV_Item, $idLV)
    Next
EndFunc   ;==>_ReadLV


Func _SaveLV()
    Local $sLV_AllItems, $hFile
    For $i = 0 To _GUICtrlListView_GetItemCount($idLV) - 1
        $sLV_AllItems &= _GUICtrlListView_GetItemTextString($idLV, $i) & @CRLF
    Next
    $sLV_AllItems = StringTrimRight($sLV_AllItems, 2)
    ;   MsgBox(0, '', $sLV_AllItems)
    FileMove($sLV_SavePath, StringReplace($sLV_SavePath, '.txt', '.bak'), $FC_OVERWRITE)
    $hFile = FileOpen($sLV_SavePath, $FO_OVERWRITE)
    FileWrite($hFile, $sLV_AllItems)
    FileClose($hFile)
EndFunc   ;==>_SaveLV

Func _exit()
    _SaveLV()
    ConsoleWrite(_GUICtrlListView_GetColumnWidth($idLV, 1) & @CRLF)
    Exit
EndFunc   ;==>_exit

Func _SortByCol()
    _GUICtrlListView_SortItems($idLV, GUICtrlGetState($idLV)) ; Einträge entsprechend sortieren
EndFunc   ;==>_SortByCol

Func _Add()
    Opt('GUIOnEventMode', 0)
    Local $msg, $sRep = 'dayly|weekly|monthly|yearly', $sEvent, $dtEvenDate, $iHour, $iMinute, $iTime, $iVal, $iBD, $iPreWarn
    $hRem = GUICreate("Add a reminder", 200, 320, -1, -1, Default, Default, $hMain)
    GUICtrlCreateLabel("Reminder Name", 10, 5, 180, 25, $ES_center)
    Local $idInpEvent = GUICtrlCreateInput("", 10, 25, 180, 20)
    Local $idDate = GUICtrlCreateMonthCal(@YEAR & "/" & @MON & "/" & @MDAY, 10, 55, 180, 160, $MCS_NOTODAY)
    GUICtrlCreateLabel("&Hour:", 5, 223, 30, 25, $SS_RIGHT)
    Local $idCboHour = GUICtrlCreateCombo("", 40, 220, 40, 25)
    GUICtrlSetData($idCboHour, "00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23")
    Local $idCboMinute = GUICtrlCreateCombo("", 140, 220, 40, 25)
    GUICtrlSetData($idCboMinute, "00|05|10|15|20|25|30|35|40|45|50|55")
    GUICtrlCreateLabel('&Repeat', 5, 245, 60, 20)
    Local $idCboRepeat = GUICtrlCreateCombo("", 5, 262, 60, 25)
    GUICtrlSetData($idCboRepeat, "no|dayly|weekly|Monthly|Yearly", "no")
    GUICtrlCreateLabel('&Value', 70, 245, 75, 20)
    Local $idVal = GUICtrlCreateEdit('', 70, 262, 45, 25, $ES_Number)
    GUICtrlCreateLabel('&Birth Year', 120, 245, 75, 20)
    Local $idBD = GUICtrlCreateEdit('', 120, 262, 45, 25, $ES_Number)
    GUICtrlCreateLabel('&Pre Warn', 170, 245, 75, 20)
    Local $idCboPreWarn = GUICtrlCreateCombo("", 170, 262, 30, 25)
    GUICtrlSetData($idCboPreWarn, "0|1|2|3|4|5", "0")
    Local $idBtnOK = GUICtrlCreateButton("&Save Reminder", 10, 292, 180, 25)
    GUICtrlSetState($idBtnOK, $GUI_DISABLE)
    GUISetState(@SW_SHOW)

    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $idInpEvent
                $sEvent = GUICtrlRead($idInpEvent)
                If $sEvent = '' Then
                    GUICtrlSetState($idBtnOK, $GUI_DISABLE)
                Else
                    GUICtrlSetState($idBtnOK, $GUI_ENABLE)
                EndIf
            Case $idBtnOK
                $dtEvenDate = GUICtrlRead($idDate)
                $iHour = '00' & GUICtrlRead($idCboHour)
                $iMinute = '00' & GUICtrlRead($idCboMinute)
                $iTime = StringRight($iHour, 2) & ":" & StringRight($iMinute, 2)
                $sRep = GUICtrlRead($idCboRepeat)
                $iVal = GUICtrlRead($idVal)
                $iBD = GUICtrlRead($idBD)
                $iPreWarn = Int(GUICtrlRead($idCboPreWarn))
                ;"Event|Date+Time|Repeated|Interval|Birthdate|PreWarn|HiddenSort"
                GUICtrlCreateListViewItem($sEvent & "|" & $dtEvenDate & ' ' & $iTime & '|' & $sRep & '|' & $iVal & '|' & $iBD & '|' & $iPreWarn & '|' & _DateAdd('d', $iPreWarn * -1, $dtEvenDate & ' ' & $iTime), $idLV)
                GUIDelete($hRem)
                ExitLoop
            Case $GUI_EVENT_CLOSE
                GUIDelete($hRem)
                ExitLoop
        EndSwitch
    WEnd
    GUISetState(BitOR(@SW_ENABLE, @SW_SHOW), $hMain)
    Opt('GUIOnEventMode', 1)
    ConsoleWrite(Opt('GUIOnEventMode') & @CRLF)
    AdlibUnRegister('_CheckRemind')
    _GUICtrlListView_BeginUpdate($idLV)
    _SaveLV()
    _GUICtrlListView_SimpleSort($idLV, $g_bSortSense, 6, False) ; Prevent sort direction toggling for next insertion
    _GUICtrlListView_EndUpdate($idLV)
    AdlibRegister('_CheckRemind', 15000)
EndFunc   ;==>_Add

Func _Delete()
    Local $aLV_Selected = _GUICtrlListView_GetSelectedIndices($idLV, True)
    ;_ArrayDisplay($aLV_Selected, 'Line 236')
    Local $sQuest
    For $i = 1 To $aLV_Selected[0]
        $sQuest &= _GUICtrlListView_GetItemTextString($idLV, $aLV_Selected[$i])
        If $i <> $aLV_Selected[0] Then $sQuest &= @CRLF
    Next
    Local $iRet = MsgBox(BitOR($MB_YESNO, $MB_ICONQUESTION), 'Delete ' & $aLV_Selected[0] & ' selected Items', $sQuest, 0, $hMain)
    If $iRet <> $IDNO Then _GUICtrlListView_DeleteItemsSelected($idLV)
EndFunc   ;==>_Delete

the messagebox "incompatible Data?" must be answered with Yes, but i suggest to save the datafile or to open it before in scite.

Edit: The Prewarn Value are the days before the EventDate+Time is first reminded (and snoozed) in a 4 hour rythmn, therefor the _CheckRemind func is enhanced and in the testing state.

Edited by AutoBert
PreWarn inserted
Posted

@AutoBert

You have started adding bells and whistles.This adds complexity to the code.

Some points that I noticed:

CheckRemider shoud return if (at the start) there is no reminder (ie If $aRemind[1] = "" Then Return) .

The add reminder Form is scrambled

Reminders are reached before the defined time. Also if I exit and restart the program todays reminders are reached.

I like your code and learn new things by examining.

Thanks

Posted (edited)
On 11/19/2022 at 9:24 AM, hawkair said:

The add reminder Form is scrambled

Ups, a typo and sleeping while testing.

 

On 11/19/2022 at 9:24 AM, hawkair said:

Reminders are reached before the defined time. Also if I exit and restart the program todays reminders are reached.

I know that _CheckRemind() isn't perfect. Should be better now with new created Reminder or already existing Reminders after moved.

#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_LegalCopyright=autoBert
#AutoIt3Wrapper_Res_Language=1031
#AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4
#AutoIt3Wrapper_Run_Tidy=y
#AutoIt3Wrapper_Run_Au3Stripper=n
#Au3Stripper_Parameters=/mo

#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <String.au3>
#include <Date.au3>
#include <File.au3>

#cs
    Nice to have (when it's done):
        Change Txt-File saving to SQLite based saving
        Split in 2 Apps: 1 for Add Data
                         1 for Alarm from Reminder
    What's to do:
        Implement checking of DateTime for alarm
        Testing (maybe enhance)
#ce

Opt('GUIOnEventMode', 1)
Global $g_bSortSense = False
Global Const $sLV_SavePath = @ScriptDir & '\Reminder.LV.txt'
Global $iMax = 0 ; no timeout
;Global $iMax = 15 ; sec timeout
Global $hMain = GUICreate("Reminder", 600, 500, -1, -1), $hRem
GUISetBkColor(0x6BC072)
Global $idLV = GUICtrlCreateListView("Event|Date+Time|Repeated|Interval|Birthdate|PreWarn|HiddenSort", 5, 5, 590, 445, BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT), BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
GUICtrlSetBkColor(-1, 0xA6D9AA)
GUICtrlSetOnEvent($idLV, '_SortByCol')
_GUICtrlListView_SetColumnWidth($idLV, 0, 200)
_GUICtrlListView_SetColumnWidth($idLV, 1, 140)
_GUICtrlListView_SetColumnWidth($idLV, 2, 80)
_GUICtrlListView_SetColumnWidth($idLV, 3, 70)
_GUICtrlListView_SetColumnWidth($idLV, 4, 36)
_GUICtrlListView_SetColumnWidth($idLV, 5, 70)
_GUICtrlListView_HideColumn($idLV, 6)

Global $idAdd = GUICtrlCreateButton("&Add a new reminder", 15, 460, 230, 30)
Global $idDelete = GUICtrlCreateButton("&Delete selected reminders", 260, 460, 230, 30)
Global $idExit = GUICtrlCreateButton("E&xit", 505, 460, 80, 30)

GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit')
GUICtrlSetOnEvent($idDelete, '_Delete')
GUICtrlSetOnEvent($idAdd, '_Add')
GUICtrlSetOnEvent($idExit, '_Exit')
_GUICtrlListView_RegisterSortCallBack($idLV) ; damit man das Listview (mit Klick auf die Spaltenüberschrift) sortieren kann
_GUICtrlListView_SortItems($idLV, 6)     ; Einträge entsprechend sortieren
_ReadLV()
GUISetState()
_CheckRemind()

While 1
    Sleep(10000)
WEnd

Func _CheckRemind()
    Local $sQuest, $sFlag, $iRet, $iDiff, $aDate, $aTime, $dtNewDate, $dtHidSort, $sTitle
    Local $aRemind = _GUICtrlListView_GetItemTextArray($idLV, 0) ;Item 0 allways oldest in remindeing-queue
    _DateTimeSplit($aRemind[2], $aDate, $aTime)
    $sQuest &= 'is reached!' & @CRLF
    If $aRemind[3] <> 'no' Then
        $sTitle &= $aRemind[1]
        $sQuest &= 'Move for ' & $aRemind[4] & ' * ' & StringTrimRight($aRemind[3], 2) & '(s) ?'
        $sFlag = BitOR($MB_ICONINFORMATION, $MB_YESNO)
    Else
        $sFlag = BitOR($MB_ICONINFORMATION, $MB_OK)
    EndIf
    ;_ArrayDisplay($aRemind, 'Line 73')
    Local $dtNow = @YEAR & '/' & @MON & '/' & @MDAY & ' ' & StringRight('00' & @HOUR, 2) & ':' & StringRight('00' & @MIN, 2)
    ConsoleWrite('line 75: ' & $dtNow & ' < ' & $aRemind[7] & ' Return? ' & ($dtNow < $aRemind[2]) & @CRLF)
    If $dtNow < $aRemind[7] Then AdlibRegister('_CheckRemind', 15000)
    If $dtNow < $aRemind[7] Then Return
    AdlibUnRegister('_CheckRemind')
    _GUICtrlListView_BeginUpdate($idLV)
    $iDiff = _DateDiff('d', $dtNow, $aRemind[7])
    ConsoleWrite('DtDiff: ' & $iDiff & @CRLF)
    ;   Exit
    If $aRemind[6] <> "" And $iDiff < 0 And $iDiff >= $aRemind[6] * -1 Then
        $dtHidSort = StringTrimRight(_DateAdd('h', 4, $dtNow), 2) & '00'
        If $dtHidSort < $aRemind[2] Then
            ConsoleWrite($aRemind[2] & '|' & $dtNow & @CRLF)
            $sTitle = $aRemind[1] & ' Pre Warning (snooze)'
            $sFlag = BitOR($MB_ICONINFORMATION, $MB_OK)
            $sQuest = 'Will be moved to  ' & $dtHidSort & '!'
        EndIf
    Else
        $sTitle &= $aRemind[1]
        $sQuest &= 'Move for ' & $aRemind[4] & ' * ' & StringTrimRight($aRemind[3], 2) & '(s) ?'
        $sFlag = BitOR($MB_ICONINFORMATION, $MB_YESNO)
    EndIf
    $iRet = MsgBox($sFlag, $sTitle & ' ' & $aRemind[2], $sQuest, $iMax, $hMain)
    If $aRemind[3] <> 'no' Then
        If $iRet <> $IDNO Then
            If StringInStr($sTitle, 'Pre Warning (snooze)') Then
                ConsoleWrite($aRemind[7] & '=>' & $dtHidSort & @CRLF)
                _GUICtrlListView_SetItemText($idLV, 0, $dtHidSort, 6)
            Else
                $dtNewDate = _DateAdd(StringLeft($aRemind[3], 1), $aRemind[4], $aDate[1] & '/' & $aDate[2] & '/' & $aDate[3] & ' ' & $aTime[1] & ':' & $aTime[2])
                ConsoleWrite($aRemind[2] & '=>' & $dtNewDate & @CRLF)
                _GUICtrlListView_SetItemText($idLV, 0, $dtNewDate, 1)
                $dtHidSort = _DateAdd('d', $aRemind[6] * -1, $dtNewDate)
                ConsoleWrite($aRemind[7] & '=>' & $dtHidSort & @CRLF)
                _GUICtrlListView_SetItemText($idLV, 0, $dtHidSort, 6)
            EndIf
        EndIf
    Else
        If $iRet <> $IDNO Then _GUICtrlListView_DeleteItem($idLV, 0)
    EndIf
    _GUICtrlListView_SimpleSort($idLV, $g_bSortSense, 6, False) ; Prevent sort direction toggling for next insertion
    _GUICtrlListView_EndUpdate($idLV)
    _SaveLV()
    AdlibRegister('_CheckRemind')
    ;to be checked
EndFunc   ;==>_CheckRemind

Func _ReadLV()
    Local $aLV, $sLV_Item, $iCols, $sQuest, $sFlag, $sTitle = 'incompatible Data?', $iRet
    _FileReadToArray($sLV_SavePath, $aLV, $FRTA_NOCOUNT, '|')
    $iCols = _GUICtrlListView_GetColumnCount($idLV)
    ConsoleWrite($iCols & '|' & UBound($aLV, 2) & @CRLF)
    If $iCols <> UBound($aLV, 2) Then ;Return
        $sQuest = 'App has ' & $iCols & ' Cols, but DataFile has ' & UBound($aLV, 2) & ' Cols.' & @CRLF & @CRLF
        $sQuest &= 'Continue anyway?'
        $sFlag = BitOR($MB_ICONINFORMATION, $MB_YESNO)
        $iRet = MsgBox($sFlag, $sTitle, $sQuest, $iMax, $hMain)
        If $iRet <> $IDYES Then Exit
    EndIf
    _ArraySort($aLV, 0, 0, 0, 6)
    _GUICtrlListView_DeleteAllItems($idLV)
    ;_ArrayDisplay($aLV, 'Line 135 ')
    If UBound($aLV, 2) < $iCols Then $iCols = UBound($aLV, 2)
    For $i = 0 To UBound($aLV, 1) - 1
        $sLV_Item = ''
        For $j = 0 To $iCols - 1
            $sLV_Item &= $aLV[$i][$j] & '|'
        Next
        $sLV_Item = StringTrimRight($sLV_Item, 1)
        GUICtrlCreateListViewItem($sLV_Item, $idLV)
    Next
EndFunc   ;==>_ReadLV


Func _SaveLV()
    Local $sLV_AllItems, $hFile
    For $i = 0 To _GUICtrlListView_GetItemCount($idLV) - 1
        $sLV_AllItems &= _GUICtrlListView_GetItemTextString($idLV, $i) & @CRLF
    Next
    $sLV_AllItems = StringTrimRight($sLV_AllItems, 2)
    ;   MsgBox(0, '', $sLV_AllItems)
    FileMove($sLV_SavePath, StringReplace($sLV_SavePath, '.txt', '.bak'), $FC_OVERWRITE)
    $hFile = FileOpen($sLV_SavePath, $FO_OVERWRITE)
    FileWrite($hFile, $sLV_AllItems)
    FileClose($hFile)
EndFunc   ;==>_SaveLV

Func _exit()
    _SaveLV()
    ConsoleWrite(_GUICtrlListView_GetColumnWidth($idLV, 1) & @CRLF)
    Exit
EndFunc   ;==>_exit

Func _SortByCol()
    _GUICtrlListView_SortItems($idLV, GUICtrlGetState($idLV)) ; Einträge entsprechend sortieren
EndFunc   ;==>_SortByCol

Func _Add()
    Opt('GUIOnEventMode', 0)
    Local $msg, $sRep = 'dayly|weekly|monthly|yearly', $sEvent, $dtEvenDate, $iHour, $iMinute, $iTime, $iVal, $iBD, $iPreWarn
    $hRem = GUICreate("Add a reminder", 200, 320, -1, -1, Default, Default, $hMain)
    GUICtrlCreateLabel("Reminder Name", 10, 5, 180, 25, $ES_center)
    Local $idInpEvent = GUICtrlCreateInput("", 10, 25, 180, 20)
    Local $idDate = GUICtrlCreateMonthCal(@YEAR & "/" & @MON & "/" & @MDAY, 10, 55, 180, 160, $MCS_NOTODAY)
    GUICtrlCreateLabel("&Hour:", 5, 223, 30, 25, $SS_RIGHT)
    Local $idCboHour = GUICtrlCreateCombo("", 40, 220, 40, 25)
    GUICtrlSetData($idCboHour, "00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23")
    Local $idCboMinute = GUICtrlCreateCombo("", 140, 220, 40, 25)
    GUICtrlSetData($idCboMinute, "00|05|10|15|20|25|30|35|40|45|50|55")
    GUICtrlCreateLabel('&Repeat', 5, 245, 60, 20)
    Local $idCboRepeat = GUICtrlCreateCombo("", 5, 262, 60, 25)
    GUICtrlSetData($idCboRepeat, "no|dayly|weekly|Monthly|Yearly", "no")
    GUICtrlCreateLabel('&Value', 70, 245, 75, 20)
    Local $idVal = GUICtrlCreateEdit('', 70, 262, 45, 25, $ES_Number)
    GUICtrlCreateLabel('&Birth Year', 120, 245, 75, 20)
    Local $idBD = GUICtrlCreateEdit('', 120, 262, 45, 25, $ES_Number)
    GUICtrlCreateLabel('&Pre Warn', 170, 245, 75, 20)
    Local $idCboPreWarn = GUICtrlCreateCombo("", 170, 262, 30, 25)
    GUICtrlSetData($idCboPreWarn, "0|1|2|3|4|5", "0")
    Local $idBtnOK = GUICtrlCreateButton("&Save Reminder", 10, 292, 180, 25)
    GUICtrlSetState($idBtnOK, $GUI_DISABLE)
    GUISetState(@SW_SHOW)

    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $idInpEvent
                $sEvent = GUICtrlRead($idInpEvent)
                If $sEvent = '' Then
                    GUICtrlSetState($idBtnOK, $GUI_DISABLE)
                Else
                    GUICtrlSetState($idBtnOK, $GUI_ENABLE)
                EndIf
            Case $idBtnOK
                $dtEvenDate = GUICtrlRead($idDate)
                $iHour = '00' & GUICtrlRead($idCboHour)
                $iMinute = '00' & GUICtrlRead($idCboMinute)
                $iTime = StringRight($iHour, 2) & ":" & StringRight($iMinute, 2)
                $sRep = GUICtrlRead($idCboRepeat)
                $iVal = GUICtrlRead($idVal)
                $iBD = GUICtrlRead($idBD)
                $iPreWarn = Int(GUICtrlRead($idCboPreWarn))
                ;"Event|Date+Time|Repeated|Interval|Birthdate|PreWarn|HiddenSort"
                GUICtrlCreateListViewItem($sEvent & "|" & $dtEvenDate & ' ' & $iTime & '|' & $sRep & '|' & $iVal & '|' & $iBD & '|' & $iPreWarn & '|' & _DateAdd('d', $iPreWarn * -1, $dtEvenDate & ' ' & $iTime), $idLV)
                GUIDelete($hRem)
                ExitLoop
            Case $GUI_EVENT_CLOSE
                GUIDelete($hRem)
                ExitLoop
        EndSwitch
    WEnd
    GUISetState(BitOR(@SW_ENABLE, @SW_SHOW), $hMain)
    Opt('GUIOnEventMode', 1)
    ConsoleWrite(Opt('GUIOnEventMode') & @CRLF)
    AdlibUnRegister('_CheckRemind')
    _GUICtrlListView_BeginUpdate($idLV)
    _SaveLV()
    _GUICtrlListView_SimpleSort($idLV, $g_bSortSense, 6, False) ; Prevent sort direction toggling for next insertion
    _GUICtrlListView_EndUpdate($idLV)
    AdlibRegister('_CheckRemind', 15000)
EndFunc   ;==>_Add

Func _Delete()
    Local $aLV_Selected = _GUICtrlListView_GetSelectedIndices($idLV, True)
    ;_ArrayDisplay($aLV_Selected, 'Line 238')
    Local $sQuest
    For $i = 1 To $aLV_Selected[0]
        $sQuest &= _GUICtrlListView_GetItemTextString($idLV, $aLV_Selected[$i])
        If $i <> $aLV_Selected[0] Then $sQuest &= @CRLF
    Next
    Local $iRet = MsgBox(BitOR($MB_YESNO, $MB_ICONQUESTION), 'Delete ' & $aLV_Selected[0] & ' selected Items', $sQuest, 0, $hMain)
    If $iRet <> $IDNO Then _GUICtrlListView_DeleteItemsSelected($idLV)
EndFunc   ;==>_Delete

 

Edited by AutoBert
Posted (edited)

@AutoBert

I am sorry I didn't mean to sound judgemental.

I am indeed greatful for the time and the effort you put into this.

I added a line in checkRemind to take care of when the LV files are empty(ie there is no reminder) and now the program works like a charm.

Whithout this line when i Started the program it repeatedly displayed the message "is reached....." and would not continue.

The first lines of the amended CheckRemind

Func _CheckRemind()
    Local $sQuest, $sFlag, $iRet, $iDiff, $aDate, $aTime, $dtNewDate, $dtHidSort, $sTitle
    Local $aRemind = _GUICtrlListView_GetItemTextArray($idLV, 0) ;Item 0 allways oldest in remindeing-queue
    If $aRemind[1] = "" Then Return
    _DateTimeSplit($aRemind[2], $aDate, $aTime)
    $sQuest &= 'is reached!' & @CRLF

 

Thanks AutoBert. Great Job!!

 

 

Edited by hawkair
a small correction was needed in the code
Posted
4 hours ago, hawkair said:

I saw what you did with the new function calls and now I should be able to do sth on my own.

Good to read

 

4 hours ago, hawkair said:

It will probably take some time though...

Maybe with my newest source a little be easier:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_LegalCopyright=autoBert
#AutoIt3Wrapper_Res_Language=1031
#AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_Run_Tidy=y
#Au3Stripper_Parameters=/mo
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <String.au3>
#include <Date.au3>
#include <File.au3>

#cs
    Nice to have (when it's done):
        Change Txt-File saving to SQLite based saving
        Split in 2 Apps: 1 for Add Data
                         1 for Alarm from Reminder
    What's to do:
        Implement checking of DateTime for alarm
        Testing (maybe enhance)
#ce

Opt('GUIOnEventMode', 1)
Global $g_bSortSense = False
Global Const $sLV_SavePath = @ScriptDir & '\Reminder.LV.txt'
Global $iMax = 0 ; no timeout
;Global $iMax = 15 ; sec timeout
Global $hMain = GUICreate("Reminder", 800, 500, -1, -1), $hRem
GUISetBkColor(0x6BC072)
Global $idLV = GUICtrlCreateListView("Event|Date+Time|Repeated|Interval|BaseYear|PreWarn|HiddenSort|PreWarn Text", 5, 5, 790, 445, BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT), BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
GUICtrlSetBkColor(-1, 0xA6D9AA)
;GUICtrlSetOnEvent($idLV, '_SortByCol')
_GUICtrlListView_SetColumnWidth($idLV, 0, 180)
_GUICtrlListView_SetColumnWidth($idLV, 1, 140)
_GUICtrlListView_SetColumnWidth($idLV, 2, 80)
_GUICtrlListView_SetColumnWidth($idLV, 3, 70)
_GUICtrlListView_SetColumnWidth($idLV, 4, 36)
_GUICtrlListView_SetColumnWidth($idLV, 5, 70)
_GUICtrlListView_SetColumnWidth($idLV, 6, 0)
_GUICtrlListView_SetColumnWidth($idLV, 7, 200)
Global $idBtnAdd = GUICtrlCreateButton("&Add a new reminder", 5, 460, 230, 30)
Global $idBtnDelete = GUICtrlCreateButton("&Delete selected reminders", 245, 460, 230, 30)
Global $idBtnEdit = GUICtrlCreateButton("&Edit first selected reminder", 480, 460, 230, 30)
;GUICtrlSetState(-1, $GUI_DISABLE)
Global $idBtnExit = GUICtrlCreateButton("E&xit", 715, 460, 80, 30)
GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit')
GUICtrlSetOnEvent($idBtnDelete, '_Delete')
GUICtrlSetOnEvent($idBtnAdd, '_AddEdit')
GUICtrlSetOnEvent($idBtnEdit, '_AddEdit')
GUICtrlSetOnEvent($idBtnExit, '_Exit')
_GUICtrlListView_RegisterSortCallBack($idLV) ; damit man das Listview (mit Klick auf die Spaltenüberschrift) sortieren kann
_GUICtrlListView_SortItems($idLV, 6)     ; Einträge entsprechend sortieren
_ReadLV()
GUISetState()
_CheckRemind()

While 1
    Sleep(10000)
WEnd

Func _CheckRemind()
    Local $sQuest, $sFlag, $iRet, $iDiff, $aDate, $aTime, $dtNewDate, $dtHidSort, $sTitle
    Local $aRemind = _GUICtrlListView_GetItemTextArray($idLV, 0) ;Item 0 allways oldest in remindeing-queue
    _DateTimeSplit($aRemind[2], $aDate, $aTime)
    $sQuest &= 'is reached!' & @CRLF
    If $aRemind[3] <> 'no' Then
        $sTitle = $aRemind[1]
        $sQuest &= 'Move for ' & $aRemind[4] & ' * ' & StringTrimRight($aRemind[3], 2) & '(s) ?'
        $sFlag = BitOR($MB_ICONQUESTION, $MB_YESNO)
    Else
        $sFlag = BitOR($MB_ICONINFORMATION, $MB_OK)
    EndIf
    ;_ArrayDisplay($aRemind, 'Line 75')
    Local $dtNow = @YEAR & '/' & @MON & '/' & @MDAY & ' ' & StringRight('00' & @HOUR, 2) & ':' & StringRight('00' & @MIN, 2)
    ;ConsoleWrite('line 77: ' & $dtNow & ' < ' & $aRemind[7] & ' Return? ' & ($dtNow < $aRemind[2]) & @CRLF)
    If $dtNow < $aRemind[7] Then AdlibRegister('_CheckRemind', 15000)
    If $dtNow < $aRemind[7] Then Return
    AdlibUnRegister('_CheckRemind')
    _GUICtrlListView_BeginUpdate($idLV)
    $iDiff = _DateDiff('d', $dtNow, $aRemind[7])
    ;ConsoleWrite('DtDiff: ' & $iDiff & @CRLF)
    ;   Exit
    If (Int($aRemind[6]) <> 0) And $iDiff < 0 And $iDiff >= $aRemind[6] * -1 Then
        $dtHidSort = StringTrimRight(_DateAdd('h', 4, $dtNow), 2) & '00'
        ;ConsoleWrite('snooze! ' & $dtHidSort & @CRLF)
        If $dtHidSort <= $aRemind[2] Then
            ;ConsoleWrite($aRemind[2] & '|' & $dtNow & @CRLF)
            $sTitle = $aRemind[1] & ' Pre Warning (snooze)'
            $sFlag = BitOR($MB_ICONINFORMATION, $MB_OK)
            $sQuest = $aRemind[8] & @CRLF & 'Next Pre Warning moved to  ' & $dtHidSort & '!'
        EndIf
    Else
        ;ConsoleWrite('normal' & @CRLF)
        $sTitle = $aRemind[1]
        If $aRemind[3] <> 'no' Then
            $sQuest &= 'is reached!' & @CRLF
            $sQuest = 'Move for ' & $aRemind[4] & ' * ' & StringTrimRight($aRemind[3], 2) & '(s) ?'
            $sFlag = BitOR($MB_ICONQUESTION, $MB_YESNO)
        Else

            $sQuest &= 'Will be deleted!'
            $sFlag = BitOR($MB_ICONINFORMATION, $MB_OK)
        EndIf
    EndIf
    $iRet = MsgBox($sFlag, $sTitle & ' ' & $aRemind[2], $sQuest, $iMax, $hMain)
    If $aRemind[3] <> 'no' Or StringInStr($sTitle, 'Pre Warning (snooze)') Then
        ;       If $iRet <> $IDNO Then
        If StringInStr($sTitle, 'Pre Warning (snooze)') Then
            ;ConsoleWrite('snooze!!' & @CRLF)
            ;ConsoleWrite($aRemind[7] & '=>' & $dtHidSort & @CRLF)
            _GUICtrlListView_SetItemText($idLV, 0, $dtHidSort, 6)
        ElseIf $aRemind[3] <> 'no' Then
            $dtNewDate = _DateAdd(StringLeft($aRemind[3], 1), $aRemind[4], $aDate[1] & '/' & $aDate[2] & '/' & $aDate[3] & ' ' & $aTime[1] & ':' & $aTime[2])
            ;ConsoleWrite($aRemind[2] & '=>' & $dtNewDate & @CRLF)
            _GUICtrlListView_SetItemText($idLV, 0, $dtNewDate, 1)
            If $aRemind[4] < 0 Then $aRemind[4] = $aRemind[4] * -1
            $dtHidSort = _DateAdd('d', $aRemind[4] * -1, $dtNewDate)
            ;ConsoleWrite($aRemind[7] & '=>' & $dtHidSort & @CRLF)
            _GUICtrlListView_SetItemText($idLV, 0, $dtHidSort, 6)
        EndIf
    EndIf
    ;   Else
    If Not (StringInStr($sTitle, 'Pre Warning (snooze)')) And $aRemind[3] = 'no' Then
        ;ConsoleWrite('delete: ' & _GUICtrlListView_GetItemTextString($idLV, 0) & @CRLF & $sFlag & @CRLF & $sQuest & @CRLF)
        If $iRet <> $IDNO And $aRemind[2] <= $dtNow Then _GUICtrlListView_DeleteItem($idLV, 0)
    EndIf
    _GUICtrlListView_SimpleSort($idLV, $g_bSortSense, 6, False) ; Prevent sort direction toggling for next insertion
    _GUICtrlListView_EndUpdate($idLV)
    _SaveLV()
    AdlibRegister('_CheckRemind')
    ;to be checked
EndFunc   ;==>_CheckRemind

Func _ReadLV()
    Local $aLV, $sLV_Item, $iCols, $sQuest, $sFlag, $sTitle = 'incompatible Data?', $iRet
    _FileReadToArray($sLV_SavePath, $aLV, $FRTA_NOCOUNT, '|')
    $iCols = _GUICtrlListView_GetColumnCount($idLV)
    ;ConsoleWrite($iCols & '|' & UBound($aLV, 2) & @CRLF)
    If $iCols <> UBound($aLV, 2) Then ;Return
        $sQuest = 'App has ' & $iCols & ' Cols, but DataFile has ' & UBound($aLV, 2) & ' Cols.' & @CRLF & @CRLF
        $sQuest &= 'Continue anyway?'
        $sFlag = BitOR($MB_ICONINFORMATION, $MB_YESNO)
        $iRet = MsgBox($sFlag, $sTitle, $sQuest, $iMax, $hMain)
        If $iRet <> $IDYES Then Exit
    EndIf
    _ArraySort($aLV, 0, 0, 0, 6)
    _GUICtrlListView_DeleteAllItems($idLV)
    ;_ArrayDisplay($aLV, 'Line 150 ')
    If UBound($aLV, 2) < $iCols Then $iCols = UBound($aLV, 2)
    For $i = 0 To UBound($aLV, 1) - 1
        $sLV_Item = ''
        For $j = 0 To $iCols - 1
            $sLV_Item &= $aLV[$i][$j] & '|'
        Next
        $sLV_Item = StringTrimRight($sLV_Item, 1)
        GUICtrlCreateListViewItem($sLV_Item, $idLV)
    Next
    _GUICtrlListView_SetColumnWidth($idLV, 6, 0)
EndFunc   ;==>_ReadLV


Func _SaveLV()
    Local $sLV_AllItems, $hFile
    For $i = 0 To _GUICtrlListView_GetItemCount($idLV) - 1
        $sLV_AllItems &= _GUICtrlListView_GetItemTextString($idLV, $i) & @CRLF
    Next
    $sLV_AllItems = StringTrimRight($sLV_AllItems, 2)
    ;   MsgBox(0, '', $sLV_AllItems)
    FileMove($sLV_SavePath, StringReplace($sLV_SavePath, '.txt', '.bak'), $FC_OVERWRITE)
    $hFile = FileOpen($sLV_SavePath, $FO_OVERWRITE)
    FileWrite($hFile, $sLV_AllItems)
    FileClose($hFile)
EndFunc   ;==>_SaveLV

Func _exit()
    _SaveLV()
    ;ConsoleWrite(_GUICtrlListView_GetColumnWidth($idLV, 1) & @CRLF)
    Exit
EndFunc   ;==>_exit
#cs
Func _SortByCol()
    _GUICtrlListView_SortItems($idLV, GUICtrlGetState($idLV)) ; Einträge entsprechend sortieren
EndFunc   ;==>_SortByCol
#ce
Func _AddEdit()
    Local $idFrom = @GUI_CtrlId, $sFrmTitle, $aSelected, $aRemind[9], $sLVItem
    Local $msg, $dtEventDate, $dtEventTime, $iHour, $iMinute
    Switch $idFrom
        Case $idBtnAdd
            $sFrmTitle = "Add a reminder"
            _DateTimeSplit(@YEAR & '/' & @MON & '/' & @MDAY & ' 08:00', $dtEventDate, $dtEventTime)
        Case $idBtnEdit
            $aSelected = _GUICtrlListView_GetSelectedIndices($idLV, True)
            If $aSelected[0] = 0 Then Return
            $sFrmTitle = "Edit reminder"
            $aRemind = _GUICtrlListView_GetItemTextArray($idLV, $aSelected[1])
            _DateTimeSplit($aRemind[2], $dtEventDate, $dtEventTime)
    EndSwitch
    ;_ArrayDisplay($aRemind)
    Opt('GUIOnEventMode', 0)
    $hRem = GUICreate($sFrmTitle, 200, 360, -1, -1, Default, Default, $hMain)
    GUICtrlCreateLabel("Reminder Name", 10, 5, 180, 25, $ES_center)
    Local $idInpEvent = GUICtrlCreateInput("", 10, 25, 180, 20)
    GUICtrlSetTip($idInpEvent, 'The Reminder Name')
    Local $idDate = GUICtrlCreateMonthCal($dtEventDate[1] & "/" & $dtEventDate[2] & "/" & $dtEventDate[3], 10, 55, 180, 160, $MCS_NOTODAY)
    GUICtrlCreateLabel("&Hour:", 5, 223, 30, 25, $SS_RIGHT)
    Local $idCboHour = GUICtrlCreateCombo("", 40, 220, 40, 25)
    GUICtrlSetData($idCboHour, "00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23")
    Local $idCboMinute = GUICtrlCreateCombo("", 140, 220, 40, 25)
    GUICtrlSetData($idCboMinute, "00|05|10|15|20|25|30|35|40|45|50|55")
    GUICtrlCreateLabel('&Repeat', 5, 245, 60, 20)
    Local $idCboRepeat = GUICtrlCreateCombo("", 5, 262, 60, 25)
    GUICtrlSetData($idCboRepeat, "no|dayly|weekly|Monthly|Yearly", "no")
    GUICtrlCreateLabel('&Value', 70, 245, 75, 20)
    Local $idInpVal = GUICtrlCreateEdit('', 70, 262, 35, 25, $ES_Number)
    GUICtrlCreateLabel('&Base', 110, 245, 75, 20)
    Local $idInpBD = GUICtrlCreateEdit('', 110, 262, 45, 25, $ES_Number)
    GUICtrlCreateLabel('&Pre Warn', 160, 245, 75, 20)
    Local $idCboPreWarn = GUICtrlCreateCombo("", 160, 262, 30, 25)
    GUICtrlSetData($idCboPreWarn, "0|1|2|3|4|5", "0")
    GUICtrlCreateLabel("Pre Warning Text", 10, 295, 180, 25, $ES_center)
    Local $idInpPrewarn = GUICtrlCreateInput("", 10, 310, 180, 20)
    Local $idBtnOK = GUICtrlCreateButton("&Save Reminder", 10, 332, 180, 25)
    Switch $idFrom
        Case $idBtnEdit
            GUICtrlSetData($idInpEvent, $aRemind[1])
            GUICtrlSetData($idCboHour, $dtEventTime[1])
            GUICtrlSetData($idCboMinute, $dtEventTime[2])
            GUICtrlSetData($idCboRepeat, $aRemind[3])
            GUICtrlSetData($idInpVal, $aRemind[4])
            GUICtrlSetData($idInpBD, $aRemind[5])
            GUICtrlSetData($idCboPreWarn, $aRemind[6])
            GUICtrlSetData($idInpPrewarn, $aRemind[8])
        Case Else
            GUICtrlSetState($idBtnOK, $GUI_DISABLE)
    EndSwitch
    GUISetState(@SW_SHOW, $hRem)

    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $idInpEvent
                $aRemind[1] = GUICtrlRead($idInpEvent)
                If $aRemind[1] = '' Then
                    GUICtrlSetState($idBtnOK, $GUI_DISABLE)
                Else
                    GUICtrlSetState($idBtnOK, $GUI_ENABLE)
                EndIf
            Case $idBtnOK
                $aRemind[1] = GUICtrlRead($idInpEvent)
                $dtEventDate = GUICtrlRead($idDate)
                $iHour = '00' & GUICtrlRead($idCboHour)
                $iMinute = '00' & GUICtrlRead($idCboMinute)
                $dtEventTime = StringRight($iHour, 2) & ":" & StringRight($iMinute, 2)
                $aRemind[2] = $dtEventDate & ' ' & $dtEventTime
                $aRemind[3] = GUICtrlRead($idCboRepeat)
                $aRemind[4] = GUICtrlRead($idInpVal)
                $aRemind[5] = GUICtrlRead($idInpBD)
                $aRemind[6] = Int(GUICtrlRead($idCboPreWarn))
                $aRemind[7] = _DateAdd('d', $aRemind[6] * -1, $aRemind[2])
                $aRemind[8] = GUICtrlRead($idInpPrewarn)
                For $i = 1 To 8
                    $sLVItem &= $aRemind[$i]
                    If $i < 8 Then $sLVItem &= '|'
                Next
                ;ConsoleWrite($sLVItem & @CRLF)
                ;"Event|Date+Time|Repeated|Interval|Birthdate|PreWarn|HiddenSort|PreWarn Text"
                ;_ArrayDisplay($aRemind)
                Switch $idFrom
                    Case $idBtnAdd
                        GUICtrlCreateListViewItem($sLVItem, $idLV)
                    Case $idBtnEdit
                        If GUICtrlCreateListViewItem($sLVItem, $idLV) > 0 Then _GUICtrlListView_DeleteItem($idLV, $aSelected[1])
                EndSwitch
                GUIDelete($hRem)
                ExitLoop
            Case $GUI_EVENT_CLOSE
                GUIDelete($hRem)
                ExitLoop
        EndSwitch
    WEnd
    GUISetState(BitOR(@SW_ENABLE, @SW_SHOW), $hMain)
    Opt('GUIOnEventMode', 1)
    ;ConsoleWrite(Opt('GUIOnEventMode') & @CRLF)
    AdlibUnRegister('_CheckRemind')
    _GUICtrlListView_BeginUpdate($idLV)
    _SaveLV()
    _GUICtrlListView_SimpleSort($idLV, $g_bSortSense, 6, False) ; Prevent sort direction toggling for next insertion
    _GUICtrlListView_EndUpdate($idLV)
    AdlibRegister('_CheckRemind', 15000)
EndFunc   ;==>_AddEdit

Func _Delete()
    Local $aLV_Selected = _GUICtrlListView_GetSelectedIndices($idLV, True)
    ;_ArrayDisplay($aLV_Selected, 'Line 296')
    Local $sQuest
    For $i = 1 To $aLV_Selected[0]
        $sQuest &= _GUICtrlListView_GetItemTextString($idLV, $aLV_Selected[$i])
        If $i <> $aLV_Selected[0] Then $sQuest &= @CRLF
    Next
    Local $iRet = MsgBox(BitOR($MB_YESNO, $MB_ICONQUESTION), 'Delete ' & $aLV_Selected[0] & ' selected Items', $sQuest, 0, $hMain)
    If $iRet <> $IDNO Then _GUICtrlListView_DeleteItemsSelected($idLV)
EndFunc   ;==>_Delete

 

Posted

The program is amazing!

I am already using it for organizing and time management and at the same time I test and do additions to suit my needs

I find it more suitable and practical than any free or paid alternative.

And I had the same thought with you to add an Edit function.

I also did some modifications in Checkremind but I didnt test the snooze function which you apparently did.

I also renamed function Add to AddReminder, Delete to DeleteReminder etc because I carry all my code in one file and I already have functions with those names.

Here is my code (When I have more time I will incorporate your additions and point out any bugs)

#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_LegalCopyright=autoBert
#AutoIt3Wrapper_Res_Language=1031
#AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4
#AutoIt3Wrapper_Run_Tidy=y
#AutoIt3Wrapper_Run_Au3Stripper=n
#Au3Stripper_Parameters=/mo

#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <String.au3>
#include <Date.au3>
#include <File.au3>

#cs
    Nice to have (when it's done):
    Change Txt-File saving to SQLite based saving
    Split in 2 Apps: 1 for Add Data
    1 for Alarm from Reminder
    What's to do:
    Implement checking of DateTime for alarm
    Testing (maybe enhance)
#ce

;~ Opt("TrayMenuMode", 1)
;~  TraySetIcon(@ScriptDir & "\Icons\Timers\3507737-alarm-clock-iconoteka-on-time-timer_107670.ico")
;~  $nTrayIcon1 = _TrayIconCreate("Title", @ScriptName, 0)
;~  _TrayIconSetState() ; Show the tray icon
;~  $nTrayMenu1 = _TrayCreateContextMenu() ;This one must exist
;~  $Tray1 = _TrayCreateItem("Tray1)
;~  _TrayItemSetIcon(-1, @ScriptName, -1)
;~  $Tray2 = _TrayCreateItem("Tray2")
;~  _TrayItemSetIcon(-1, @ScriptName, -2)
;~ $addReminderItem = TrayCreateItem("Add reminder")
;~ TrayCreateItem('')
;~ $show = TrayCreateItem("Open Reminder...")
;~ $exitItem = TrayCreateItem("Exit")
;~ $trayMsg = TrayGetMsg()
;~ Case $trayMsg = $addReminderItem

Opt('GUIOnEventMode', 1)
Global $g_bSortSense = False
Global Const $sLV_SavePath = @ScriptDir & '\Reminder.LV.txt'
Global $iMax = 0 ; no timeout
;Global $iMax = 15 ; sec timeout
Global $hMain = GUICreate("Reminder", 600, 500, -1, -1), $hRem
GUISetBkColor(0x6BC072)
Global $idLV = GUICtrlCreateListView("Event|Date+Time|Repeated|Interval|Birthdate|PreWarn|HiddenSort", 5, 5, 590, 445, BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT), BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
GUICtrlSetBkColor(-1, 0xA6D9AA)
GUICtrlSetOnEvent($idLV, '_SortByCol')
_GUICtrlListView_SetColumnWidth($idLV, 0, 200)
_GUICtrlListView_SetColumnWidth($idLV, 1, 140)
_GUICtrlListView_SetColumnWidth($idLV, 2, 80)
_GUICtrlListView_SetColumnWidth($idLV, 3, 70)
_GUICtrlListView_SetColumnWidth($idLV, 4, 36)
_GUICtrlListView_SetColumnWidth($idLV, 5, 70)
_GUICtrlListView_HideColumn($idLV, 6)
Local $BtnInterval = 15, $BtnWid = 150
Global $idAdd = GUICtrlCreateButton("&Add a new reminder", $BtnInterval, 460, $BtnWid, 30)
Global $idDelete = GUICtrlCreateButton("&Delete selected reminders", $BtnInterval + ($BtnWid + $BtnInterval), 460, $BtnWid, 30)
Global $idEdit = GUICtrlCreateButton("&Edit selected reminder", $BtnInterval + 2 * ($BtnWid + $BtnInterval), 460, $BtnWid, 30)
Global $idExit = GUICtrlCreateButton("E&xit", $BtnInterval + 3 * ($BtnWid + $BtnInterval), 460, 80, 30)

GUISetOnEvent($GUI_EVENT_CLOSE, '_ExitReminder')
GUICtrlSetOnEvent($idDelete, '_DeleteReminder')
GUICtrlSetOnEvent($idAdd, '_AddReminder')
GUICtrlSetOnEvent($idEdit, '_EditReminder')
GUICtrlSetOnEvent($idExit, '_ExitReminder')
_GUICtrlListView_RegisterSortCallBack($idLV) ; damit man das Listview (mit Klick auf die Spaltenuberschrift) sortieren kann
_GUICtrlListView_SortItems($idLV, 6) ; Eintrage entsprechend sortieren
_ReadLV()
GUISetState()
_CheckRemind()

While 1
    Sleep(10000)
WEnd
Exit

Func _CheckRemind()
    Local $sQuest, $sFlag, $iRet, $iDiff, $aDate, $aTime, $dtNewDate, $dtHidSort, $sTitle
    Local $aRemind = _GUICtrlListView_GetItemTextArray($idLV, 0) ;Item 0 allways oldest in remindeing-queue
    If $aRemind[1] = "" Then Return
    ;_ArrayDisplay($aRemind, 'Line 73')
    Local $dtNow = @YEAR & '/' & @MON & '/' & @MDAY & ' ' & StringRight('00' & @HOUR, 2) & ':' & StringRight('00' & @MIN, 2)
    ConsoleWrite('line 75: ' & $dtNow & ' < ' & $aRemind[7] & ' Return? ' & ($dtNow < $aRemind[2]) & @CRLF)
    If $dtNow < $aRemind[7] Then AdlibRegister('_CheckRemind', 15000)
    If $dtNow < $aRemind[7] Then Return
    _DateTimeSplit($aRemind[2], $aDate, $aTime)

    $sQuest &= 'is reached!' & @CRLF
    If $aRemind[3] <> 'no' Then
        $sTitle &= $aRemind[1]
        $sQuest &= 'Move for ' & $aRemind[4] & ' * ' & StringTrimRight($aRemind[3], 2) & '(s) ?'
        $sFlag = BitOR($MB_ICONINFORMATION, $MB_YESNO)
    Else
        $sFlag = BitOR($MB_ICONINFORMATION, $MB_OK)
    EndIf
    AdlibUnRegister('_CheckRemind')
    _GUICtrlListView_BeginUpdate($idLV)
    $iDiff = _DateDiff('d', $dtNow, $aRemind[7])
    ConsoleWrite('DtDiff: ' & $iDiff & @CRLF)
    ;   Exit
    If $aRemind[6] <> "" And $iDiff < 0 And $iDiff >= $aRemind[6] * -1 Then
        $dtHidSort = StringTrimRight(_DateAdd('h', 4, $dtNow), 2) & '00'
        If $dtHidSort < $aRemind[2] Then
            ConsoleWrite($aRemind[2] & '|' & $dtNow & @CRLF)
            $sTitle = $aRemind[1] & ' Pre Warning (snooze)'
            $sFlag = BitOR($MB_ICONINFORMATION, $MB_OK)
            $sQuest = 'Will be moved to  ' & $dtHidSort & '!'
        EndIf
    Else
;~      $sTitle &= $aRemind[1]
        $sTitle = $aRemind[1]
;~      $sQuest &= 'Move for ' & $aRemind[4] & ' * ' & StringTrimRight($aRemind[3], 2) & '(s) ?'
        $sQuest = 'Repeat in ' & $aRemind[4] & ' * ' & StringTrimRight($aRemind[3], 2) & '(s) ?'
        $sFlag = BitOR($MB_ICONINFORMATION, $MB_YESNO)
    EndIf
    $iRet = MsgBox($sFlag, $sTitle & ' ' & $aRemind[2], $sQuest, $iMax, $hMain)
    If $aRemind[3] <> 'no' Then;Repeated Reminder
        If $iRet <> $IDNO Then; Yes, do Repeat
            If StringInStr($sTitle, 'Pre Warning (snooze)') Then
                ConsoleWrite($aRemind[7] & '=>' & $dtHidSort & @CRLF)
                _GUICtrlListView_SetItemText($idLV, 0, $dtHidSort, 6)
            Else
                $dtNewDate = _DateAdd(StringLeft($aRemind[3], 1), $aRemind[4], $aDate[1] & '/' & $aDate[2] & '/' & $aDate[3] & ' ' & $aTime[1] & ':' & $aTime[2])
                ConsoleWrite($aRemind[2] & '=>' & $dtNewDate & @CRLF)
                _GUICtrlListView_SetItemText($idLV, 0, $dtNewDate, 1)
                $dtHidSort = _DateAdd('d', $aRemind[6] * -1, $dtNewDate)
                ConsoleWrite($aRemind[7] & '=>' & $dtHidSort & @CRLF)
                _GUICtrlListView_SetItemText($idLV, 0, $dtHidSort, 6)
            EndIf
        Else; No do NOT Repeat
            _GUICtrlListView_DeleteItem($idLV, 0)
        EndIf
    Else; NOT Repeated Reminder
        _GUICtrlListView_DeleteItem($idLV, 0)
    EndIf
    _GUICtrlListView_SimpleSort($idLV, $g_bSortSense, 6, False) ; Prevent sort direction toggling for next insertion
    _GUICtrlListView_EndUpdate($idLV)
    _SaveLV()
    AdlibRegister('_CheckRemind')
    ;to be checked
EndFunc   ;==>_CheckRemind

Func _ReadLV()
    Local $aLV, $sLV_Item, $iCols, $sQuest, $sFlag, $sTitle = 'incompatible Data?', $iRet
    _FileReadToArray($sLV_SavePath, $aLV, $FRTA_NOCOUNT, '|')
    $iCols = _GUICtrlListView_GetColumnCount($idLV)
    ConsoleWrite($iCols & '|' & UBound($aLV, 2) & @CRLF)
    If $iCols <> UBound($aLV, 2) Then ;Return
        $sQuest = 'App has ' & $iCols & ' Cols, but DataFile has ' & UBound($aLV, 2) & ' Cols.' & @CRLF & @CRLF
        $sQuest &= 'Continue anyway?'
        $sFlag = BitOR($MB_ICONINFORMATION, $MB_YESNO)
        $iRet = MsgBox($sFlag, $sTitle, $sQuest, $iMax, $hMain)
        If $iRet <> $IDYES Then Exit
    EndIf
    _ArraySort($aLV, 0, 0, 0, 6)
    _GUICtrlListView_DeleteAllItems($idLV)
    ;_ArrayDisplay($aLV, 'Line 135 ')
    If UBound($aLV, 2) < $iCols Then $iCols = UBound($aLV, 2)
    For $i = 0 To UBound($aLV, 1) - 1
        $sLV_Item = ''
        For $j = 0 To $iCols - 1
            $sLV_Item &= $aLV[$i][$j] & '|'
        Next
        $sLV_Item = StringTrimRight($sLV_Item, 1)
        GUICtrlCreateListViewItem($sLV_Item, $idLV)
    Next
EndFunc   ;==>_ReadLV


Func _SaveLV()
    Local $sLV_AllItems, $hFile
    For $i = 0 To _GUICtrlListView_GetItemCount($idLV) - 1
        $sLV_AllItems &= _GUICtrlListView_GetItemTextString($idLV, $i) & @CRLF
    Next
    $sLV_AllItems = StringTrimRight($sLV_AllItems, 2)
    ;   MsgBox(0, '', $sLV_AllItems)
    FileMove($sLV_SavePath, StringReplace($sLV_SavePath, '.txt', '.bak'), $FC_OVERWRITE)
    $hFile = FileOpen($sLV_SavePath, $FO_OVERWRITE)
    FileWrite($hFile, $sLV_AllItems)
    FileClose($hFile)
EndFunc   ;==>_SaveLV

Func _ExitReminder()
    _SaveLV()
    ConsoleWrite(_GUICtrlListView_GetColumnWidth($idLV, 1) & @CRLF)
    Exit
EndFunc   ;==>_ExitReminder

Func _SortByCol()
    _GUICtrlListView_SortItems($idLV, GUICtrlGetState($idLV)) ; Eintrage entsprechend sortieren
EndFunc   ;==>_SortByCol

Func _AddReminder()
    Opt('GUIOnEventMode', 0)
    Local $msg, $sRep = 'dayly|weekly|monthly|yearly', $sEvent, $dtEvenDate, $iHour, $iMinute, $iTime, $iVal, $iBD, $iPreWarn
    $hRem = GUICreate("Add a reminder", 200, 320, -1, -1, Default, Default, $hMain)
    GUICtrlCreateLabel("Reminder Name", 10, 5, 180, 25, $ES_center)
    Local $idInpEvent = GUICtrlCreateInput("", 10, 25, 180, 20)
    Local $idDate = GUICtrlCreateMonthCal(@YEAR & "/" & @MON & "/" & @MDAY, 10, 55, 180, 160, $MCS_NOTODAY)
    GUICtrlCreateLabel("&Hour:", 5, 223, 30, 25, $SS_RIGHT)
    Local $idCboHour = GUICtrlCreateCombo("08", 40, 220, 40, 25)
    GUICtrlSetData($idCboHour, "00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23")
    Local $idCboMinute = GUICtrlCreateCombo("00", 140, 220, 40, 25)
    GUICtrlSetData($idCboMinute, "00|05|10|15|20|25|30|35|40|45|50|55")
    GUICtrlCreateLabel('&Repeat', 5, 245, 60, 20)
    Local $idCboRepeat = GUICtrlCreateCombo("", 5, 262, 60, 25)
    GUICtrlSetData($idCboRepeat, "no|dayly|weekly|Monthly|Yearly", "no")
    GUICtrlCreateLabel('&Value', 70, 245, 75, 20)
    Local $idVal = GUICtrlCreateEdit('', 70, 262, 45, 25, $ES_Number)
    GUICtrlCreateLabel('&Birth Year', 120, 245, 75, 20)
    Local $idBD = GUICtrlCreateEdit('', 120, 262, 45, 25, $ES_Number)
    GUICtrlCreateLabel('&Pre Warn', 170, 245, 75, 20)
    Local $idCboPreWarn = GUICtrlCreateCombo("", 170, 262, 30, 25)
    GUICtrlSetData($idCboPreWarn, "0|1|2|3|4|5", "0")
    Local $idBtnOK = GUICtrlCreateButton("&Save Reminder", 10, 292, 180, 25)
    GUICtrlSetState($idBtnOK, $GUI_DISABLE)
    GUISetState(@SW_SHOW)

    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $idInpEvent
                $sEvent = GUICtrlRead($idInpEvent)
                If $sEvent = '' Then
                    GUICtrlSetState($idBtnOK, $GUI_DISABLE)
                Else
                    GUICtrlSetState($idBtnOK, $GUI_ENABLE)
                EndIf
            Case $idBtnOK
                $dtEvenDate = GUICtrlRead($idDate)
                $iHour = '00' & GUICtrlRead($idCboHour)
                $iMinute = '00' & GUICtrlRead($idCboMinute)
                $iTime = StringRight($iHour, 2) & ":" & StringRight($iMinute, 2)
                $sRep = GUICtrlRead($idCboRepeat)
                $iVal = GUICtrlRead($idVal)
                $iBD = GUICtrlRead($idBD)
                $iPreWarn = Int(GUICtrlRead($idCboPreWarn))
                ;"Event|Date+Time|Repeated|Interval|Birthdate|PreWarn|HiddenSort"
                GUICtrlCreateListViewItem($sEvent & "|" & $dtEvenDate & ' ' & $iTime & '|' & $sRep & '|' & $iVal & '|' & $iBD & '|' & $iPreWarn & '|' & _DateAdd('d', $iPreWarn * -1, $dtEvenDate & ' ' & $iTime), $idLV)
                GUIDelete($hRem)
                ExitLoop
            Case $GUI_EVENT_CLOSE
                GUIDelete($hRem)
                ExitLoop
        EndSwitch
    WEnd
    GUISetState(BitOR(@SW_ENABLE, @SW_SHOW), $hMain)
    Opt('GUIOnEventMode', 1)
    ConsoleWrite(Opt('GUIOnEventMode') & @CRLF)
    AdlibUnRegister('_CheckRemind')
    _GUICtrlListView_BeginUpdate($idLV)
    _SaveLV()
    _GUICtrlListView_SimpleSort($idLV, $g_bSortSense, 6, False) ; Prevent sort direction toggling for next insertion
    _GUICtrlListView_EndUpdate($idLV)
    AdlibRegister('_CheckRemind', 15000)
EndFunc   ;==>_AddReminder

Func _EditReminder()
    Opt('GUIOnEventMode', 0)
    Local $tmp, $sDate, $aTime, $sQuest
    Local $aLV_Selected = _GUICtrlListView_GetSelectedIndices($idLV, True)
    ;_ArrayDisplay($aLV_Selected, 'Line 238')
    If $aLV_Selected[0] = 0 Then
        Opt('GUIOnEventMode', 1)
        Return MsgBox(262144, "No action", "nothing selected", 2)
    EndIf
    Local $aRemind = _GUICtrlListView_GetItemTextArray($idLV, $aLV_Selected[1])
;~  _ArrayDisplay ($aRemind)
    $tmp = StringSplit($aRemind[2], " ", 2)
    $sDate = $tmp[0]
    $aTime = StringSplit($tmp[1], ":", 2)

    Local $msg, $sRep = 'daily|weekly|monthly|yearly', $sEvent, $dtEvenDate, $iHour, $iMinute, $iTime, $iVal, $iBD, $iPreWarn
    $hRem = GUICreate("Edit a reminder", 200, 320, -1, -1, Default, Default, $hMain)
    GUICtrlCreateLabel("Reminder Name", 10, 5, 180, 25, $ES_center)
    Local $idInpEvent = GUICtrlCreateInput($aRemind[1], 10, 25, 180, 20)
    Local $idDate = GUICtrlCreateMonthCal($sDate, 10, 55, 180, 160, $MCS_NOTODAY)
    GUICtrlCreateLabel("&Hour:", 5, 223, 30, 25, $SS_RIGHT)
    Local $idCboHour = GUICtrlCreateCombo($aTime[0], 40, 220, 40, 25)
    GUICtrlSetData($idCboHour, "00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23")
    Local $idCboMinute = GUICtrlCreateCombo($aTime[1], 140, 220, 40, 25)
    GUICtrlSetData($idCboMinute, "00|05|10|15|20|25|30|35|40|45|50|55")
    GUICtrlCreateLabel('&Repeat', 5, 245, 60, 20)
    Local $idCboRepeat = GUICtrlCreateCombo($aRemind[3], 5, 262, 60, 25)
    GUICtrlSetData($idCboRepeat, "no|daily|weekly|Monthly|Yearly", $aRemind[3])
    GUICtrlCreateLabel('&Value', 70, 245, 75, 20)
    Local $idVal = GUICtrlCreateEdit($aRemind[4], 70, 262, 45, 25, $ES_Number)
    GUICtrlCreateLabel('&Birth Year', 120, 245, 75, 20)
    Local $idBD = GUICtrlCreateEdit($aRemind[5], 120, 262, 45, 25, $ES_Number)
    GUICtrlCreateLabel('&Pre Warn', 170, 245, 75, 20)
    Local $idCboPreWarn = GUICtrlCreateCombo($aRemind[6], 170, 262, 30, 25)
    GUICtrlSetData($idCboPreWarn, "0|1|2|3|4|5", "0")
    Local $idBtnOK = GUICtrlCreateButton("&Save Reminder", 10, 292, 180, 25)
    GUICtrlSetState($idBtnOK, $GUI_DISABLE)
    GUISetState(@SW_SHOW)

    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $idInpEvent, $idDate, $idCboHour, $idCboMinute, $idCboRepeat, $idVal, $idBD, $idCboPreWarn
                $sEvent = GUICtrlRead($idInpEvent)
                If $sEvent = '' Then
                    GUICtrlSetState($idBtnOK, $GUI_DISABLE)
                Else
                    GUICtrlSetState($idBtnOK, $GUI_ENABLE)
                EndIf
            Case $idBtnOK
                $dtEvenDate = GUICtrlRead($idDate)
                $iHour = '00' & GUICtrlRead($idCboHour)
                $iMinute = '00' & GUICtrlRead($idCboMinute)
                $iTime = StringRight($iHour, 2) & ":" & StringRight($iMinute, 2)
                $sRep = GUICtrlRead($idCboRepeat)
                $iVal = GUICtrlRead($idVal)
                $iBD = GUICtrlRead($idBD)
                $iPreWarn = Int(GUICtrlRead($idCboPreWarn))
                ;"Event|Date+Time|Repeated|Interval|Birthdate|PreWarn|HiddenSort"
                GUICtrlCreateListViewItem($sEvent & "|" & $dtEvenDate & ' ' & $iTime & '|' & $sRep & '|' & $iVal & '|' & $iBD & '|' & $iPreWarn & '|' & _DateAdd('d', $iPreWarn * -1, $dtEvenDate & ' ' & $iTime), $idLV)
                $sQuest = _GUICtrlListView_GetItemTextString($idLV, $aLV_Selected[1])
                Local $iRet = MsgBox(BitOR($MB_YESNO, $MB_ICONQUESTION), 'Remove ' & $aLV_Selected[0] & ' original reminder?', $sQuest, 0, $hMain)
                If $iRet <> $IDNO Then _GUICtrlListView_DeleteItem($idLV, $aLV_Selected[1])
                GUIDelete($hRem)
                ExitLoop
            Case $GUI_EVENT_CLOSE
                GUIDelete($hRem)
                ExitLoop
        EndSwitch
    WEnd
    GUISetState(BitOR(@SW_ENABLE, @SW_SHOW), $hMain)
    Opt('GUIOnEventMode', 1)
    ConsoleWrite(Opt('GUIOnEventMode') & @CRLF)
    AdlibUnRegister('_CheckRemind')
    _GUICtrlListView_BeginUpdate($idLV)
    _SaveLV()
    _GUICtrlListView_SimpleSort($idLV, $g_bSortSense, 6, False) ; Prevent sort direction toggling for next insertion
    _GUICtrlListView_EndUpdate($idLV)
    AdlibRegister('_CheckRemind', 15000)
EndFunc   ;==>_EditReminder

Func _DeleteReminder()
    Local $aLV_Selected = _GUICtrlListView_GetSelectedIndices($idLV, True)
    ;_ArrayDisplay($aLV_Selected, 'Line 238')
    Local $sQuest
    For $i = 1 To $aLV_Selected[0]
        $sQuest &= _GUICtrlListView_GetItemTextString($idLV, $aLV_Selected[$i])
        If $i <> $aLV_Selected[0] Then $sQuest &= @CRLF
    Next
    Local $iRet = MsgBox(BitOR($MB_YESNO, $MB_ICONQUESTION), 'Delete ' & $aLV_Selected[0] & ' selected Items', $sQuest, 0, $hMain)
    If $iRet <> $IDNO Then _GUICtrlListView_DeleteItemsSelected($idLV)
EndFunc   ;==>_DeleteReminder

 

  • 3 weeks later...
Posted (edited)

Data file?

Func _SeedLV()
    Local $sLV_AllItems, $hFile

    $sLV_AllItems = "A reminder|2023/12/26 23:55|no|1|1|1|2023/12/25 23:55|A warning" & @CRLF

    $sLV_AllItems = StringTrimRight($sLV_AllItems, 2)
    MsgBox(0, 'Seed', $sLV_AllItems)
    FileMove($sLV_SavePath, StringReplace($sLV_SavePath, '.txt', '.bak'), $FC_OVERWRITE)
    $hFile = FileOpen($sLV_SavePath, $FO_OVERWRITE)
    FileWrite($hFile, $sLV_AllItems)
    FileClose($hFile)
EndFunc   ;==>_SeedLV

Add this function where appropriate. I placed it directly after the 

If $iRet <> $IDYES Then

I could help with the SQL implementation, but I need to see what you are working with at the moment

S

Edited by Skysnake

Skysnake

Why is the snake in the sky?

Posted
On 12/14/2022 at 4:26 PM, Skysnake said:

Data file?

Func _SeedLV()
    Local $sLV_AllItems, $hFile

    $sLV_AllItems = "A reminder|2023/12/26 23:55|no|1|1|1|2023/12/25 23:55|A warning" & @CRLF

    $sLV_AllItems = StringTrimRight($sLV_AllItems, 2)
    MsgBox(0, 'Seed', $sLV_AllItems)
    FileMove($sLV_SavePath, StringReplace($sLV_SavePath, '.txt', '.bak'), $FC_OVERWRITE)
    $hFile = FileOpen($sLV_SavePath, $FO_OVERWRITE)
    FileWrite($hFile, $sLV_AllItems)
    FileClose($hFile)
EndFunc   ;==>_SeedLV

Add this function where appropriate. I placed it directly after the 

If $iRet <> $IDYES Then

I could help with the SQL implementation, but I need to see what you are working with at the moment

S

Hi

at least in my version the program creates the datafile when you add the first reminder so so as far as I can see _SeedLV is not necessary

The comment about SQL was Autobert's or from the initial code. At the moment I have aroud 40-50 Reminders and a text datafile presents no problem

but it would be nice to see how it could be implemented.

I want to say that it is still a work in progress, I am still experimenting, if I dont feel sth is absolutely necessary it stays on the shelves indefinetly.

And last but not least I am a lousy coder so excuse the messy code:

#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_LegalCopyright=autoBert
#AutoIt3Wrapper_Res_Language=1031
#AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4
#AutoIt3Wrapper_Run_Tidy=y
#AutoIt3Wrapper_Run_Au3Stripper=n
#Au3Stripper_Parameters=/mo

#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <String.au3>
#include <Date.au3>
#include <File.au3>
#include <Math.au3>

#cs
    Nice to have (when it's done):
    Change Txt-File saving to SQLite based saving
    Split in 2 Apps: 1 for Add Data
    1 for Alarm from Reminder
    What's to do:
    Implement checking of DateTime for alarm
    Testing (maybe enhance)
#ce


#cs
    ;~ Sth I may add..
    Opt("TrayMenuMode", 1)
    $nTrayIcon1 = _TrayIconCreate("Title", @ScriptName, 0)
    _TrayIconSetState() ; Show the tray icon
    $nTrayMenu1 = _TrayCreateContextMenu() ;This one must exist
    $Tray1 = _TrayCreateItem("Tray1)
    _TrayItemSetIcon(-1, @ScriptName, -1)
    $Tray2 = _TrayCreateItem("Tray2")
    _TrayItemSetIcon(-1, @ScriptName, -2)
    $addReminderItem = TrayCreateItem("Add reminder")
    TrayCreateItem('')
    $show = TrayCreateItem("Open Reminder...")
    $exitItem = TrayCreateItem("Exit")
    $trayMsg = TrayGetMsg()
    Case $trayMsg = $addReminderItem
#CE

;/========Change History========/
;Still a work in progress, So please Excuse the messy coding..
;14/12/2022 modified checkremind. Instead of asking confirmation about everything, like should I repeat a repeated Reminder or should I delete a non-repeated one,
;I decided to use a gui that allows to either acknowlegde Alarm(Done) Remind Again at xx Days/Hours/Minutes, or Remove Alarm altogether regardless if repeated or not
;If I acknowledge then repeated tasks get repeated, non repeated get removed as initially intended without extra confirmation.
;Tweaked AddEdit a bit to compress code
;Added option to have named events like "EndoFHome" "EndOfWork"(These run at the times I leave home or work) in order to perform some tasks and then
;close the program so that the DataFile that I keep in Dropbox gets updated
;Other events may be "Shutdown", "LogOff". One may add whatever else is desirable
;Adding a new reminder proposes Current Time instead of 00:00
;Started tweaking Gui/Control positions/dimensions which I define as variables so that it's easier to make small changes without drowning in numbers
;EditReminder asks if you want to remove original reminder. Answering no makes it work like CopyReminder

Global $ProgTtitle = "Reminder"
Global $WorkPC = "WorkPC", $HomePC = "HomePC"

If WinExists($ProgTtitle, "E&xit") Then Exit WinActivate($ProgTtitle);Do not continue if program is already running- Just Activate it
TraySetIcon(@ScriptDir & "\Icons\Timers\3507737-alarm-clock-iconoteka-on-time-timer_107670.ico")
Global Const $sLV_SavePath = @ScriptDir & '\Reminder.LV.txt'
Opt('GUIOnEventMode', 1)
Global $g_bSortSense = False

Global $iMax = 0 ; no timeout
;Global $iMax = 15 ; sec timeout
Global $GuiWid = 700, $GuiHeight = 700, $iBtns = 4, $aBtnStart[$iBtns], $BtnInterval = 15, $BtnBorder = 10, $BtnWid = Int(($GuiWid - 2 * $BtnBorder - $BtnInterval * $iBtns) / $iBtns), $BtnHeight = 30, $BtnLineY = $GuiHeight - $BtnHeight - $BtnBorder, $LVBorder = 5, $LVWid = $GuiWid - 2 * $LVBorder, $LVHeight = $GuiHeight - $BtnHeight - 2 * $BtnBorder
Global $hMain = GUICreate($ProgTtitle, $GuiWid, $GuiHeight, -1, -1), $hRem
GUISetBkColor(0x6BC072)
;~ Global $idLV = GUICtrlCreateListView("Event|Date+Time|Repeated|Interval|BaseYear|PreWarn|HiddenSort|PreWarn Text", 5, 5, 790, 445, BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT), BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
Global $idLV = GUICtrlCreateListView("Event|Date+Time|Repeated|Interval|BaseYear|PreWarn|HiddenSort|PreWarn Text", $LVBorder, $LVBorder, $LVWid, $LVHeight, BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT), BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
GUICtrlSetBkColor(-1, 0xA6D9AA)
;~ GUICtrlSetOnEvent($idLV, '_SortByCol')
_GUICtrlListView_SetColumnWidth($idLV, 0, 220)
_GUICtrlListView_SetColumnWidth($idLV, 1, 100)
_GUICtrlListView_SetColumnWidth($idLV, 2, 80)
_GUICtrlListView_SetColumnWidth($idLV, 3, 70)
_GUICtrlListView_SetColumnWidth($idLV, 4, 36)
_GUICtrlListView_SetColumnWidth($idLV, 5, 70)
_GUICtrlListView_SetColumnWidth($idLV, 6, 0)
_GUICtrlListView_SetColumnWidth($idLV, 7, 200)

$aBtnStart[0] = $BtnInterval
For $i = 1 To $iBtns - 1
    $aBtnStart[$i] = $aBtnStart[$i - 1] + $BtnWid + $BtnInterval
Next

Global $idBtnAdd = GUICtrlCreateButton("&Add a new reminder", $aBtnStart[0], $BtnLineY, $BtnWid, $BtnHeight)
Global $idBtnDelete = GUICtrlCreateButton("&Delete selected reminders", $aBtnStart[1], $BtnLineY, $BtnWid, $BtnHeight)
Global $idBtnEdit = GUICtrlCreateButton("&Edit selected reminder", $aBtnStart[2], $BtnLineY, $BtnWid, $BtnHeight)
Global $idBtnExit = GUICtrlCreateButton("E&xit", $aBtnStart[3], $BtnLineY, $BtnWid, $BtnHeight)

GUISetOnEvent($GUI_EVENT_CLOSE, '_ExitReminder')
GUICtrlSetOnEvent($idBtnDelete, '_DeleteReminder')
GUICtrlSetOnEvent($idBtnAdd, '_AddEditReminder')
GUICtrlSetOnEvent($idBtnEdit, '_AddEditReminder')
GUICtrlSetOnEvent($idBtnExit, '_ExitReminder')
_GUICtrlListView_RegisterSortCallBack($idLV) ; damit man das Listview (mit Klick auf die Spaltenuberschrift) sortieren kann
_GUICtrlListView_SortItems($idLV, 6) ; Eintrage entsprechend sortieren
_ReadLV()
GUISetState()
_CheckRemind()

While 1
    Sleep(10000)
WEnd


Func _CheckRemind()
    Local $sQuest, $sFlag, $iRet, $iDiff, $aDate, $aTime, $dtNewDate, $dtHidSort, $sTitle
    Local $aRemind = _GUICtrlListView_GetItemTextArray($idLV, 0) ;Item 0 allways oldest in remindeing-queue
    If $aRemind[1] = "" Then Return
    ;_ArrayDisplay($aRemind, 'Line 73')
    Local $dtNow = @YEAR & '/' & @MON & '/' & @MDAY & ' ' & StringRight('00' & @HOUR, 2) & ':' & StringRight('00' & @MIN, 2)
    ConsoleWrite('line 75: ' & $dtNow & ' < ' & $aRemind[7] & ' Return? ' & ($dtNow < $aRemind[2]) & @CRLF)
    If $dtNow < $aRemind[7] Then AdlibRegister('_CheckRemind', 15000)
    If $dtNow < $aRemind[7] Then Return

    _DateTimeSplit($aRemind[2], $aDate, $aTime)

    Switch $aRemind[1]
        Case "EndofWork", "EndofHome";Two task to exit program when I close my PC when I leave Home or Office so it reads the Updated File from Dropbox when i start it at the other Location
            $dtNewDate = _DateAdd('d', 1, $aRemind[2])
            _GUICtrlListView_SetItemText($idLV, 0, $dtNewDate, 1)
            _GUICtrlListView_SetItemText($idLV, 0, $dtNewDate, 6)
            _GUICtrlListView_SimpleSort($idLV, $g_bSortSense, 6, False) ; Prevent sort direction toggling for next insertion
            _GUICtrlListView_EndUpdate($idLV)
            _SaveLV()
            If @WDAY = 1 Or @WDAY = 7 Then Return;Sun/Sat
            WinClose("Lib:")
            If @ComputerName = $WorkPC And $aRemind[1] = "EndofWork" Then Exit MsgBox(262144, "Exiting", $aRemind[1] & $aRemind[2] & ">" & $dtNewDate, 2)
            If @ComputerName = $HomePC And $aRemind[1] = "EndofHome" Then Exit MsgBox(262144, "Exiting", $aRemind[1] & $aRemind[2] & ">" & $dtNewDate, 2)
            Return
        Case "Shutdown"
            Shutdown($SD_SHUTDOWN)
        Case "LogOff"
            Shutdown($SD_LOGOFF)
    EndSwitch

    Local $iDays, $iHours, $iMinutes
    Local $Border = 10, $MsgLen = StringLen($aRemind[1]), $GuiWid = _Max(_Min($MsgLen * 12, 1200), 250)
    Local $GuiHeight = 200, $iBtns = 3, $aBtnStart[$iBtns], $BtnInterval = 10, $BtnBorder = $Border, $BtnWid = Int(($GuiWid - 2 * $BtnBorder - $BtnInterval * $iBtns) / $iBtns), $BtnHeight = 25, $BtnLineY = $GuiHeight - $BtnHeight - $BtnBorder, $LVBorder = 5, $LVWid = $GuiWid - 2 * $LVBorder, $LVHeight = $GuiHeight - $BtnHeight - 2 * $BtnBorder
    Local $LabelWid3 = 30, $LabelWid = $GuiWid - 2 * $Border, $LblHeight = 25, $iLbls = 3, $aLblStart[$iLbls], $aCboStart[$iLbls], $LblInterval = 10, $LblBorder = $Border, $CboWid = 40
    $aBtnStart[0] = $BtnInterval
    For $i = 1 To $iBtns - 1
        $aBtnStart[$i] = $aBtnStart[$i - 1] + $BtnWid + $BtnInterval
    Next
    $aLblStart[0] = $Border
    $aCboStart[0] = $aLblStart[0] + $LabelWid3 + 2
    For $i = 1 To $iLbls - 1
        $aLblStart[$i] = $aLblStart[$i - 1] + $LabelWid3 + $CboWid + $LblInterval
        $aCboStart[$i] = $aLblStart[$i] + $LabelWid3 + 2
    Next
    Local $aLabelTop = [5, 35, 70, 100, 130], $CboTop = $aLabelTop[4] - 2
    Local $sFrmTitle = "Reminder Alert"
    Local $msg, $dtEventDate, $dtEventTime, $iHour, $iMinute
    _DateTimeSplit($aRemind[2], $dtEventDate, $dtEventTime)
;~     _ArrayDisplay($aRemind)
    Opt('GUIOnEventMode', 0)
    $hRem = GUICreate($sFrmTitle, $GuiWid, $GuiHeight, -1, -1, Default, $WS_EX_TOPMOST, $hMain)
    GUICtrlCreateLabel($aRemind[1], $Border, $aLabelTop[0], $LabelWid, 25, $ES_center)
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUICtrlSetFont(-1, 12, 600)
    GUICtrlSetBkColor(-1, 0x2e2e2e)
    GUICtrlCreateLabel($aRemind[2], $Border, $aLabelTop[1], $LabelWid, 25, $ES_center)
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUICtrlSetFont(-1, 12, 600)
    GUICtrlSetBkColor(-1, 0x2e2e2e)
;~     Local $idDate = GUICtrlCreateMonthCal($dtEventDate[1] & "/" & $dtEventDate[2] & "/" & $dtEventDate[3], 10, 55, 200, 160, $MCS_NOTODAY)
    GUICtrlCreateLabel("Repeated:" & $aRemind[3] & ' ' & $aRemind[4], $Border, $aLabelTop[2], $LabelWid, $LblHeight, $ES_center)
    GUICtrlCreateLabel("Remind Again In:", $Border, $aLabelTop[3], $LabelWid, $LblHeight, $SS_LEFT)
    GUICtrlCreateLabel("&Days:", $aLblStart[0], $aLabelTop[4], $LabelWid3, $LblHeight, $SS_RIGHT)
    Local $idCboDays = GUICtrlCreateCombo("00", $aCboStart[0], $CboTop, $CboWid, $LblHeight)
    GUICtrlSetData($idCboDays, "00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24")
    GUICtrlCreateLabel("&Hours:", $aLblStart[1], $aLabelTop[4], $LabelWid3, $LblHeight, $SS_RIGHT)
    Local $idCboHours = GUICtrlCreateCombo("00", $aCboStart[1], $CboTop, $CboWid, $LblHeight)
    GUICtrlSetData($idCboHours, "00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23")
    GUICtrlCreateLabel("&Mins:", $aLblStart[2], $aLabelTop[4], $LabelWid3, $LblHeight, $SS_RIGHT)
    Local $idCboMinutes = GUICtrlCreateCombo("00", $aCboStart[2], $CboTop, $CboWid, $LblHeight)
    GUICtrlSetData($idCboMinutes, "00|05|10|15|20|25|30|35|40|45|50|55|60")
    Local $idBtnDone = GUICtrlCreateButton("&Done", $aBtnStart[0], $BtnLineY, $BtnWid, $BtnHeight)
    Local $idBtnSnooze = GUICtrlCreateButton("&Snooze", $aBtnStart[1], $BtnLineY, $BtnWid, $BtnHeight)
    Local $idBtnDelete = GUICtrlCreateButton("&Delete", $aBtnStart[2], $BtnLineY, $BtnWid, $BtnHeight)

    GUISetState(@SW_SHOW, $hRem)

    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $idBtnSnooze
;~              MsgBox (262144,"Exiting", "$idBtnSnooze")
                $iDays = GUICtrlRead($idCboDays)
                $iHours = GUICtrlRead($idCboHours)
                $iMinutes = GUICtrlRead($idCboMinutes)
                If $iDays < 0 Or $iHours < 0 Or $iMinutes < 0 Then ContinueLoop
                If $iDays = 0 And $iHours = 0 And $iMinutes = 0 Then ContinueLoop
                $dtHidSort = @YEAR & '/' & @MON & '/' & @MDAY & ' ' & StringRight('00' & @HOUR, 2) & ':' & StringRight('00' & @MIN, 2)
                If $iDays > 0 Then $dtHidSort = _DateAdd('d', $iDays, $dtHidSort)
                If $iHours > 0 Then $dtHidSort = _DateAdd('h', $iHours, $dtHidSort)
                If $iMinutes > 0 Then $dtHidSort = _DateAdd('n', $iMinutes, $dtHidSort)
                _GUICtrlListView_SetItemText($idLV, 0, $dtHidSort, 6)
                ExitLoop
            Case $idBtnDelete
;~              MsgBox (262144,"Exiting", "$idBtnDelete")
                _GUICtrlListView_DeleteItem($idLV, 0)
                ExitLoop
            Case $idBtnDone, $GUI_EVENT_CLOSE
;~              MsgBox (262144,$aRemind[1], $aRemind[2])
                If $aRemind[3] = 'no' Then
                    _GUICtrlListView_DeleteItem($idLV, 0)
                Else
                    ;Intend to do: If event is daily with starting date 20/10/2022 and program has not run for some days of if i define an event with a past date then reminders will pop up for as many days until today
                    ;Also intend to define repeated event LastDayOfMonth or FirstDayOf Month
                    ;$FirstMonthDay=_DateAdd('m', 1, @YEAR & '/' & @MON & '/01' )
                    ;$LastMonthDay=_DateAdd('d', -1, $FirstMonthDay )
                    ;$LastMonthDay=$FirstMonthDay with Prewarn 1 day
                    ;$LastMonthDay=@YEAR & '/' & @MON & '/' & _DateDaysInMonth( @YEAR,@MON )
                    ;An Event with start 01/01/2020 and 2 months period will alert multiple times until Date reaches current day
;~                  $iDiff = _DateDiff(StringLeft($aRemind[3], 1), $dtNow, $aRemind[2]);Basic Periods(Y,M,d) past since initial Date
                    ;                   $dtNewDate = _DateAdd(StringLeft($aRemind[3], 1), (Int($iDiff/$aRemind[4])+1)*$aRemind[4],$aRemind[2]);Repeats+1
                    ;                   $dtNewDate = _DateAdd(StringLeft($aRemind[3], 1), (Int(_DateDiff(StringLeft($aRemind[3], 1), $dtNow, $aRemind[2])/$aRemind[4])+1)*$aRemind[4],$aRemind[2]);Repeats+1
;~                  $LastMonthDay = @YEAR & '/' & @MON & '/' + _DateDaysInMonth( @YEAR,@MON )
;~                  $LastMonthDay = @YEAR & '/01/31'
;~                  $dtHidSort = @YEAR & '/' & @MON+1 & '/01' & ' ' & $aTime[1] & ':' & $aTime[2]
                    $dtNewDate = _DateAdd(StringLeft($aRemind[3], 1), $aRemind[4], $aDate[1] & '/' & $aDate[2] & '/' & $aDate[3] & ' ' & $aTime[1] & ':' & $aTime[2])
                    _GUICtrlListView_SetItemText($idLV, 0, $dtNewDate, 1)
                    $dtHidSort = _DateAdd('d', $aRemind[6] * -1, $dtNewDate)
                    _GUICtrlListView_SetItemText($idLV, 0, $dtHidSort, 6)
                EndIf
                ExitLoop
        EndSwitch
    WEnd
    GUIDelete($hRem)
    GUISetState(BitOR(@SW_ENABLE, @SW_SHOW), $hMain)
    Opt('GUIOnEventMode', 1)
    AdlibUnRegister('_CheckRemind')
    _GUICtrlListView_BeginUpdate($idLV)
    _SaveLV()
    _GUICtrlListView_SimpleSort($idLV, $g_bSortSense, 6, False) ; Prevent sort direction toggling for next insertion
    _GUICtrlListView_EndUpdate($idLV)
    AdlibRegister('_CheckRemind', 15000)
EndFunc   ;==>_CheckRemind

Func _ReadLV()
    Local $aLV, $sLV_Item, $iCols, $sQuest, $sFlag, $sTitle = 'incompatible Data?', $iRet
    _FileReadToArray($sLV_SavePath, $aLV, $FRTA_NOCOUNT, '|')
    $iCols = _GUICtrlListView_GetColumnCount($idLV)
;~  ConsoleWrite($iCols & '|' & UBound($aLV, 2) & @CRLF)
    If $iCols <> UBound($aLV, 2) Then ;Return
        $sQuest = 'App has ' & $iCols & ' Cols, but DataFile has ' & UBound($aLV, 2) & ' Cols.' & @CRLF & @CRLF
        $sQuest &= 'Continue anyway?'
        $sFlag = BitOR($MB_ICONINFORMATION, $MB_YESNO)
        $iRet = MsgBox($sFlag, $sTitle, $sQuest, $iMax, $hMain)
        If $iRet <> $IDYES Then Exit
    EndIf
    _ArraySort($aLV, 0, 0, 0, 6)
    _GUICtrlListView_DeleteAllItems($idLV)
    ;_ArrayDisplay($aLV, 'Line 135 ')
    If UBound($aLV, 2) < $iCols Then $iCols = UBound($aLV, 2)
    For $i = 0 To UBound($aLV, 1) - 1
        $sLV_Item = ''
        For $j = 0 To $iCols - 1
            $sLV_Item &= $aLV[$i][$j] & '|'
        Next
        $sLV_Item = StringTrimRight($sLV_Item, 1)
        GUICtrlCreateListViewItem($sLV_Item, $idLV)
        GUICtrlSetTip($sLV_Item, $aLV[$i][1])
    Next
    _GUICtrlListView_SetColumnWidth($idLV, 6, 0)
EndFunc   ;==>_ReadLV


Func _SaveLV()
    Local $sLV_AllItems, $hFile
    For $i = 0 To _GUICtrlListView_GetItemCount($idLV) - 1
        $sLV_AllItems &= _GUICtrlListView_GetItemTextString($idLV, $i) & @CRLF
    Next
    $sLV_AllItems = StringTrimRight($sLV_AllItems, 2)
    ;   MsgBox(0, '', $sLV_AllItems)
    FileMove($sLV_SavePath, StringReplace($sLV_SavePath, '.txt', '.bak'), $FC_OVERWRITE)
    $hFile = FileOpen($sLV_SavePath, $FO_OVERWRITE)
    FileWrite($hFile, $sLV_AllItems)
    FileClose($hFile)
EndFunc   ;==>_SaveLV

Func _ExitReminder()
    _SaveLV()
    ConsoleWrite(_GUICtrlListView_GetColumnWidth($idLV, 1) & @CRLF)
    Exit
EndFunc   ;==>_ExitReminder

Func _SortByCol()
    _GUICtrlListView_SortItems($idLV, GUICtrlGetState($idLV)) ; Eintrage entsprechend sortieren
EndFunc   ;==>_SortByCol

Func _AddEditReminder()
    Local $idFrom = @GUI_CtrlId, $sFrmTitle, $aSelected, $aRemind[9], $sLVItem
    Local $msg, $dtEventDate, $dtEventTime, $iHour, $iMinute, $sQuest
    Local $aLabelLine = [180, 223, 245, 295], $BtnTop = 332, $BtnWidth = 200, $BtnHeight = 25
    Switch $idFrom
        Case $idBtnAdd
            $sFrmTitle = "Add a reminder"
;~             $aRemind = StringSplit ("|" & @YEAR & '/' & @MON & '/' & @MDAY & ' 08:00' & "|no|||0|2022/12/01 00:00|","|");name|2022/12/01 00:00|no|||0|2022/12/01 00:00|
            $aRemind = StringSplit("|" & @YEAR & '/' & @MON & '/' & @MDAY & ' ' & @HOUR & ":" & @MIN & "|no|||0|2022/12/01 00:00|", "|");name|2022/12/01 00:00|no|||0|2022/12/01 00:00|
        Case $idBtnEdit
            $aSelected = _GUICtrlListView_GetSelectedIndices($idLV, True)
            If $aSelected[0] = 0 Then Return
            $sFrmTitle = "Edit reminder"
            $aRemind = _GUICtrlListView_GetItemTextArray($idLV, $aSelected[1])
    EndSwitch
    _DateTimeSplit($aRemind[2], $dtEventDate, $dtEventTime)
    ;_ArrayDisplay($aRemind)
    Opt('GUIOnEventMode', 0)
    $hRem = GUICreate($sFrmTitle, 220, 360, -1, -1, Default, Default, $hMain)
    GUICtrlCreateLabel("Reminder Name", 10, $aLabelLine[0], 180, 25, $ES_center)
    Local $idInpEvent = GUICtrlCreateInput($aRemind[1], 10, 25, 200, 20)
    GUICtrlSetTip($idInpEvent, 'The Reminder Name')
    Local $idDate = GUICtrlCreateMonthCal($dtEventDate[1] & "/" & $dtEventDate[2] & "/" & $dtEventDate[3], 10, 55, 200, 160, $MCS_NOTODAY)
    GUICtrlCreateLabel("&Hour:", 5, $aLabelLine[1], 30, 25, $SS_RIGHT)
    Local $idCboHour = GUICtrlCreateCombo($dtEventTime[1], 40, 220, 40, 25)
    GUICtrlSetData($idCboHour, "00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23")
    GUICtrlCreateLabel("&Minute:", 90, $aLabelLine[1], 40, 25, $SS_RIGHT)
    Local $idCboMinute = GUICtrlCreateCombo($dtEventTime[2], 140, 220, 40, 25)
    GUICtrlSetData($idCboMinute, "00|05|10|15|20|25|30|35|40|45|50|55")
    GUICtrlCreateLabel('&Repeat', 5, $aLabelLine[2], 60, 20)
    Local $idCboRepeat = GUICtrlCreateCombo($aRemind[3], 5, 262, 60, 25)
    GUICtrlSetData($idCboRepeat, "no|daily|weekly|Monthly|Yearly");, "no")
    GUICtrlCreateLabel('&Value', 70, $aLabelLine[2], 75, 20)
    Local $idInpVal = GUICtrlCreateEdit($aRemind[4], 70, 262, 35, 25, $ES_Number)
    GUICtrlCreateLabel('&Base', 110, $aLabelLine[2], 75, 20)
    Local $idInpBD = GUICtrlCreateEdit($aRemind[5], 110, 262, 45, 25, $ES_Number)
    GUICtrlCreateLabel('&Pre Warn', 160, $aLabelLine[2], 75, 20)
    Local $idCboPreWarn = GUICtrlCreateCombo($aRemind[6], 160, 262, 30, 25)
    GUICtrlSetData($idCboPreWarn, "0|1|2|3|4|5");, "0")
    GUICtrlCreateLabel("Pre Warning Text", 10, $aLabelLine[3], 200, 25, $ES_center)
    Local $idInpPrewarn = GUICtrlCreateInput($aRemind[8], 10, 310, 200, 20)
    Local $idBtnOK = GUICtrlCreateButton("&Save Reminder", 10, $BtnTop, $BtnWidth, $BtnHeight)
    If $idFrom <> $idBtnEdit Then GUICtrlSetState($idBtnOK, $GUI_DISABLE)
    GUISetState(@SW_SHOW, $hRem)

    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $idInpEvent
                $aRemind[1] = GUICtrlRead($idInpEvent)
                If $aRemind[1] = '' Then
                    GUICtrlSetState($idBtnOK, $GUI_DISABLE)
                Else
                    GUICtrlSetState($idBtnOK, $GUI_ENABLE)
                EndIf
            Case $idBtnOK
                $aRemind[1] = GUICtrlRead($idInpEvent)
                $dtEventDate = GUICtrlRead($idDate)
                $iHour = '00' & GUICtrlRead($idCboHour)
                $iMinute = '00' & GUICtrlRead($idCboMinute)
                $dtEventTime = StringRight($iHour, 2) & ":" & StringRight($iMinute, 2)
                $aRemind[2] = $dtEventDate & ' ' & $dtEventTime
                $aRemind[3] = GUICtrlRead($idCboRepeat)
                $aRemind[4] = GUICtrlRead($idInpVal)
                $aRemind[5] = GUICtrlRead($idInpBD)
                $aRemind[6] = Int(GUICtrlRead($idCboPreWarn))
                $aRemind[7] = _DateAdd('d', $aRemind[6] * -1, $aRemind[2])
                $aRemind[8] = GUICtrlRead($idInpPrewarn)
                For $i = 1 To 8
                    $sLVItem &= $aRemind[$i]
                    If $i < 8 Then $sLVItem &= '|'
                Next
                ;ConsoleWrite($sLVItem & @CRLF)
                ;"Event|Date+Time|Repeated|Interval|Birthdate|PreWarn|HiddenSort|PreWarn Text"
                ;_ArrayDisplay($aRemind)
                Switch $idFrom
                    Case $idBtnAdd
                        GUICtrlCreateListViewItem($sLVItem, $idLV)
                    Case $idBtnEdit
                        GUICtrlCreateListViewItem($sLVItem, $idLV)
                        $sQuest = _GUICtrlListView_GetItemTextString($idLV, $aSelected[1])
                        Local $iRet = MsgBox(BitOR($MB_YESNO, $MB_ICONQUESTION), 'Remove ' & $aSelected[0] & ' original reminder?', $sQuest, 0, $hMain)
                        If $iRet <> $IDNO Then _GUICtrlListView_DeleteItem($idLV, $aSelected[1])

;~                         If GUICtrlCreateListViewItem($sLVItem, $idLV) > 0 Then _GUICtrlListView_DeleteItem($idLV, $aSelected[1])
                EndSwitch
                GUIDelete($hRem)
                ExitLoop
            Case $GUI_EVENT_CLOSE
                GUIDelete($hRem)
                ExitLoop
        EndSwitch
    WEnd
    GUISetState(BitOR(@SW_ENABLE, @SW_SHOW), $hMain)
    Opt('GUIOnEventMode', 1)
    ;ConsoleWrite(Opt('GUIOnEventMode') & @CRLF)
    AdlibUnRegister('_CheckRemind')
    _GUICtrlListView_BeginUpdate($idLV)
    _SaveLV()
    _GUICtrlListView_SimpleSort($idLV, $g_bSortSense, 6, False) ; Prevent sort direction toggling for next insertion
    _GUICtrlListView_EndUpdate($idLV)
    AdlibRegister('_CheckRemind', 15000)
EndFunc   ;==>_AddEditReminder

Func _DeleteReminder()
    Local $aLV_Selected = _GUICtrlListView_GetSelectedIndices($idLV, True)
    ;_ArrayDisplay($aLV_Selected, 'Line 238')
    Local $sQuest
    For $i = 1 To $aLV_Selected[0]
        $sQuest &= _GUICtrlListView_GetItemTextString($idLV, $aLV_Selected[$i])
        If $i <> $aLV_Selected[0] Then $sQuest &= @CRLF
    Next
    Local $iRet = MsgBox(BitOR($MB_YESNO, $MB_ICONQUESTION), 'Delete ' & $aLV_Selected[0] & ' selected Items', $sQuest, 0, $hMain)
    If $iRet <> $IDNO Then _GUICtrlListView_DeleteItemsSelected($idLV)
EndFunc   ;==>_DeleteReminder

 

  • 2 weeks later...
Posted (edited)

I have been thinking about this project. It reflects many scripting skills not easily acquired. Perhaps this can be turned into a tutorial of sorts. It is functional, has a clear purpose and in itself may be useful to other users.

PS Adding SQL / database capability will allow adding functionality such as contact details and pre-defining certain reminder types. 

Skysnake

Edited by Skysnake

Skysnake

Why is the snake in the sky?

Posted
On 12/30/2022 at 6:01 PM, Skysnake said:

I have been thinking about this project. It reflects many scripting skills not easily acquired. Perhaps this can be turned into a tutorial of sorts. It is functional, has a clear purpose and in itself may be useful to other users.

PS Adding SQL / database capability will allow adding functionality such as contact details and pre-defining certain reminder types. 

Skynsnake

I agree. I could never have done it without AutoBerts expertise on ListViews. Even though it covers my needs as is,  I am open to ideas for improvement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...