Jump to content

ComboBox updating items


Recommended Posts

You are very kind to have spent this much time helping me and explaining the steps to your GENIUS...it is going to take me some time to peruse through this and match it to the code. I hope to gain a better understanding of this, so that I may help myself and maybe later 'play it forward'

I will be back tomorrow...to really take this apart. Again, I thank your for your help and really for your time.

 

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

Okay...I have updated your comments into my (our) script. Disregard the checkboxes, as I am still working that out, but can you take a look at what I added to the array, and to the combo update, as for chores that can be performed more than one in a week, I added that ability (1,3,7) days. Can you take a peek at my code, and see if it can be reduced, as I tried many different approaches to figure out how to get info, but I was/am at a loss.

Here is the updated code...

#cs
    You wanted to have 1,2,4 week intervals which forces us to store the required interval, so why not in the same array as the chores themselves?
    Using this same array to store the chores already selected in each week is therefore a sensible choice as it keeps everything together.

    The next step follows on from something I learnt a long time ago and which I pass on with pleasure.
    When faced with a long repetitive task (such as which combos need changing) humans tend to look for the changes so as to minimize
    the number of times things need to be done.  However, computers are usually faster running the whole list of tasks as that means there
    are fewer conditional statements to run for each item - and they are usually so fast that humans do not notice the passage of time required in any event.
    So when a combo is actioned we do not look at that particular combo, we just read the whole set and recalculate and reset the combo contents for the entire GUI.
    It seems illogical, but believe me it is usually by far the best and fastest way to go about things.

    The chore removal logic is the same as I developed for your first query
    - just expanded to cater for the fact that we have 4 separate lists for the 4 weeks.
    As I have mentioned previously, choosing the right data structure and loop elements initially makes subsequent coding easier
    - this is I am afraid mostly (painfully gained) experience and there is no magic formula.
    But I would stress that it often pays to go back and completely restructure your initial data storage and
    various loop parameters if by so doing you can make the intensive parts of the script easier to code
    - the time spent is well worth it in terms of clarity of code and speed of execution.
#ce
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>

#include <Array.au3>

;         Chore([22][6]),           interval (1, 2, 4 weeks),   Count in week 1,2,3,4   , interval (1, 3, 7, days), count in days 1,2,3,4,5,6,7
Global $aChoresBase[22][14] = [ _
        ['Kitchen', 1, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0], _
        ['Master Bed Room', 1, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0], _
        ['Front Bed Room', 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Back Bed Room', 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Bathroom Full', 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Bathroom Half', 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Living Room', 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Dining Bar', 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Dining Porch', 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Basement', 4, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Garage', 4, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Laundry Room', 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Lawn (Cutting)', 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Storage', 4, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Porch', 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Closed Porch', 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Weed Pulling', 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Misc1', 4, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Misc2', 4, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Misc3', 4, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Misc4', 4, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Misc5', 4, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]]

;_ArrayDisplay($aChoresBase, "Original", Default, 8) ; Display only

If 1 = 1 Then
    ; Set default string for days of the week
    For $x = 0 To UBound($aChoresBase) - 1
        For $y = 7 To 13
            $aChoresBase[$x][$y] = '0,0,0,0'
            ;If $x = 0 Then $aChoresBase[$x][$y] = '0,0,5,0'
        Next
    Next

    ;_ArrayDisplay($aChoresBase, "Original", Default, 8) ; Display only
EndIf

; Create combo list
$sChoreListBase = ""
For $i = 0 To UBound($aChoresBase) - 1
    $sChoreListBase &= "|" & $aChoresBase[$i][0]
Next

Global $cCombo_Start, $cCheckBox_Start, $ahCheckBox

CreateSchedule()

Func CreateSchedule()

    Local $hMainGui = GUICreate('Chore List', 1200, 540)

    ; Create labels
    Local $iWeekSpacing = 125, $iWeekOffset = 90 ; 125, 90
    For $i = 1 To 4
        GUICtrlCreateLabel('Week ' & $i, 10, ($i * $iWeekSpacing) - $iWeekOffset)
    Next
    Local $iDaySpacing = 155, $iDayOffset = 45 ; 155, 45
    Local $aDay[8] = ["", 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
    For $i = 1 To 7
        GUICtrlCreateLabel($aDay[$i], $iDaySpacing * ($i) - $iDayOffset, 10, 125, 20, $SS_CENTER)
    Next

    ; Create combos
    $cCombo_Start = GUICtrlCreateDummy() + 1 ; ControlID of first combo
    Local $iComboOffset = 21, $iChoresPerDay = 5, $iComboMoveLeft = 0 ;-35

    For $i = 1 To 4 ; Weeks
        $iY_Base = ($i * $iWeekSpacing) - $iWeekOffset
        For $j = 1 To 7 ; Days
            $iX = ($iDaySpacing * $j) - $iDayOffset + $iComboMoveLeft
            For $k = 0 To $iChoresPerDay - 1 ; Chores
                $iY = $iY_Base + ($iComboOffset * $k)
                GUICtrlCreateCombo("", $iX, $iY, 125, 20)
                GUICtrlSetData(-1, $sChoreListBase)
            Next
        Next
    Next
    $cCombo_End = GUICtrlCreateDummy() - 1 ; ControlID of last combo

    Local $ahCheckBox[140][4], $iCountCheckBox = 0
    ; Create CheckBoxes
    For $i = 1 To 4 ; Weeks
        For $j = 1 To 7 ; Days
            $iX = ($iDaySpacing * $j) - $iDayOffset + $iComboMoveLeft + 134
            For $k = 0 To $iChoresPerDay - 1 ; Chores
                $iY = $iY_Base + ($iComboOffset * $k) + 4
                $iY_Base = ($i * $iWeekSpacing) - $iWeekOffset
                $ahCheckBox[$iCountCheckBox][0] = GUICtrlCreateCheckbox('', $iX, $iY, 13, 13, $BS_AUTO3STATE) ;244,39 ; $BS_3STATE , $BS_AUTO3STATE

                $iCountCheckBox += 1
            Next
        Next
    Next
    ;_ArrayDisplay($ahCheckBox)

    GUISetState()
Local $iCount_Blink = 0
    While 1
        $iMsg = GUIGetMsg()
        Switch $iMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $cCombo_Start To $cCombo_End ; Combo actioned
                _Update_Combos()

        EndSwitch
        ;$iMsg = GUIGetMsg()
        Local $bBlink = False
        For $x = 0 To UBound($ahCheckBox) - 1
            If $iMsg = $ahCheckBox[$x][0] Then
                ;
                ;If BitAND(GUICtrlRead($ahCheckBox[$x]), $GUI_CHECKED) = $GUI_CHECKED  Then
                ;
                ;ConsoleWrite('wtf' & @CRLF)
                ;MsgBox('', '', _Update_ChcekBox($ahCheckBox, $x, $iChoresPerDay))
                $bBlink = _Update_ChcekBox($ahCheckBox, $x, $iChoresPerDay)
            ElseIf $ahCheckBox[$x][3] <> '' Then
                Local $ijunk = GUICtrlGetState($ahCheckBox[$x][0])
                ;MsgBox('','',$ijunk)
                ;GUICtrlSetState($ahCheckBox[$x][0], $GUI_INDETERMINATE)
                ;ContinueLoop
If Mod($iCount_Blink, 55) = 0 Or $iCount_Blink = 0 Then
                If  BitAND(GUICtrlRead($ahCheckBox[$x][0]), $GUI_UNCHECKED) = $GUI_UNCHECKED Then
                    GUICtrlSetState($ahCheckBox[$x][0], $GUI_INDETERMINATE)
                Else
                    ;MsgBox('','',$ijunk)
                GUICtrlSetState($ahCheckBox[$x][0], $GUI_UNCHECKED)
            EndIf
            EndIf
            $iCount_Blink += 1
                ContinueLoop
                 ;$GUI_INDETERMINATE
                MsgBox('','Paused','State = ' & GUICtrlGetState($ahCheckBox[$x][0]) _
                & @CRLF & ' $GUI_CHECKED ' & $GUI_CHECKED _
                & @CRLF & ' $GUI_UNCHECKED ' & $GUI_UNCHECKED _
                & @CRLF & ' $GUI_INDETERMINATE ' & $GUI_INDETERMINATE _
                & @CRLF & ' ' _
                )

                ; $GUI_UNCHECKED Radio, Checkbox or ListViewItem will be unchecked.
    ; $GUI_CHECKED Radio, Checkbox or ListViewItem will be checked.
    ; $GUI_INDETERMINATE Checkbox having the tristate attribute will be greyed.

                If  1=1 Then

                EndIf
            EndIf
        Next
    WEnd


EndFunc   ;==>CreateSchedule
;
Func _Update_ChcekBox(ByRef $ahCheckBox, $iIndex, $iChoresPerDay)
    ;MsgBox('', 'Update Check Boxed Called', 'Index ' & $iIndex)
    ; $GUI_UNCHECKED Radio, Checkbox or ListViewItem will be unchecked.
    ; $GUI_CHECKED Radio, Checkbox or ListViewItem will be checked.
    ; $GUI_INDETERMINATE Checkbox having the tristate attribute will be greyed.

    If BitAND(GUICtrlRead($ahCheckBox[$iIndex][0]), $GUI_CHECKED) = $GUI_CHECKED Then
        ConsoleWrite('!>' & '$GUI_CHECKED ' & $ahCheckBox[$iIndex][3] & @CRLF)
        GUICtrlSetState($ahCheckBox[$iIndex][0], $GUI_INDETERMINATE)
        If $ahCheckBox[$iIndex][3] = '' Then
            $ahCheckBox[$iIndex][1] = TimerInit()
            $ahCheckBox[$iIndex][2] = 'Timer Started...'
        ElseIf $ahCheckBox[$iIndex][3] <> '' Then
            $ahCheckBox[$iIndex][1] = TimerInit()
            $ahCheckBox[$iIndex][2] = 'Timer RE-Started...'
        EndIf
    ElseIf BitAND(GUICtrlRead($ahCheckBox[$iIndex][0]), $GUI_INDETERMINATE) = $GUI_INDETERMINATE Then
        ConsoleWrite(' $GUI_INDETERMINATE' & @CRLF)
        ;GUICtrlSetState($ahCheckBox[$iIndex][0], $GUI_UNCHECKED)
        ;$ahCheckBox[$iIndex][2] = 'Timer Cleard...'
        ;$ahCheckBox[$iIndex][2] = Round(TimerDiff($ahCheckBox[$iIndex][1])/1000, 2)
        ;$ahCheckBox[$iIndex][3] = $iTotalTime
    ElseIf BitAND(GUICtrlRead($ahCheckBox[$iIndex][0]), $GUI_UNCHECKED) = $GUI_UNCHECKED Then
        ConsoleWrite('Unchecked?' & @CRLF)
        Local $iCurrent = TimerDiff($ahCheckBox[$iIndex][1])
        $iCurrent += $ahCheckBox[$iIndex][3]
        $iCurrent = $iCurrent / 1000
        Local $iTotalTime = Round($iCurrent, 2)

        If MsgBox(4, 'Complete?', 'Was the task completed?') = 6 Then

            If $iTotalTime >= 60 Then
                $ahCheckBox[$iIndex][2] = '00:' & Int($iTotalTime / 60) & ':' & Mod($iTotalTime, 60)
                ConsoleWrite('$GUI_UNCHECKED' & @CRLF)
                GUICtrlSetState($ahCheckBox[$iIndex][0], $GUI_CHECKED)
                ;$ahCheckBox[$iIndex][3] = '1' ; Reset time
            Else
                $ahCheckBox[$iIndex][2] = '00:' & Int($iTotalTime / 60) & ':' & Mod($iTotalTime, 60)
            EndIf

            MsgBox('', 'Total Time:', $iTotalTime)

        Else
            $ahCheckBox[$iIndex][2] = 'Timer Paused...'
            $ahCheckBox[$iIndex][3] = $iTotalTime
        EndIf

    EndIf

    Return $ahCheckBox[$iIndex][2]; time start on checked, time end on indeterminate
EndFunc   ;==>_Update_ChcekBox
;
Func _Update_Combos()
    ;Static $iTimesPerWeek = 0
    ; First we create a copy of the $aChores array so we can see what is and is not set this time around.
    Local $aChores = $aChoresBase
    Local $iTimesPerWeek1 = 0, $iTimesPerWeek2 = 0, $iTimesPerWeek3 = 0, $iTimesPerWeek4 = 0
    Local $aDaysTaged
    ; Read data from all combos into new blank chores array
    ; Then we read all the combos - see how we can read each week in turn by running through in sections of 35.
    ; Then if there is a value already set, we find the element of the $aChores array that matches the selected chore and set the correct "week" element
    ;(which we can easily calculate from the week number).
    ; Now we will have the array filled with all the currently selected chores and the weeks in which they have been selected.
    Local $iNextDay = 0
    Local $aWeeks
    Local $iOffsetChoreWeek = 0
    For $i = 0 To 3 ; Weeks
        ;
        ;
        $iNextDay = 0
        ;
        If $i >= 1 Then $iOffsetChoreWeek += 1
        ;
        For $j = 0 To 34 ; Combos
            ; Used for both the next day of the week and also to offset the array index with $iOffsetChoreWeek
            If Mod($j, 5) = 0 And $j <> 0 Then $iNextDay += 1

            ; Read combo setting - ControlID calculated
            $sSel = GUICtrlRead($cCombo_Start + $j + ($i * 35))

            If $sSel Then
                ; Find index of selected chore in the array
                $iIndex = _ArraySearch($aChores, $sSel)
                ; Set for correct week
                $aChores[$iIndex][$i + 2] += 1 ; Set week true
                ;
                ; it is dropping down one index on the second week???
                ; fixed by minus value of $iOffsetChoreWeek
                $aWeeks = StringSplit($aChores[$iIndex][$i + 7 + $iNextDay - $iOffsetChoreWeek], ',', 2)
                ;
                Switch $i
                    Case 0
                        $aWeeks[0] += 1
                    Case 1
                        $aWeeks[1] += 1
                    Case 2
                        $aWeeks[2] += 1
                    Case 3
                        $aWeeks[3] += 1
                EndSwitch

                $aChores[$iIndex][$i + 7 + $iNextDay - $iOffsetChoreWeek] = _ArrayToString($aWeeks, ',') ; Set Day true

            EndIf
        Next
    Next
    ;_ArrayDisplay($aChores, "Up To Date", Default, 8) ; Display only

    ; Copy base combo list - one for each week
    ; We then create a $aChoreList array with each week being given a full list of the chores to carry out
    ; - we need to have 4 as some chores are weekly and might still be selectable in other weeks.
    Local $aChoreList[5] = ["", $sChoreListBase & "|", $sChoreListBase & "|", $sChoreListBase & "|", $sChoreListBase & "|"]

    ; The next task is to remove from each list those chores which are already being carried out
    ; - so first we need to check how often the chores need to be done:

    ; once a week means remove from that week only;
    ; every 2 weeks means removes from a 2 week block if already done;
    ; while every 4 weeks means remove from all of  lists.
    ; We run through each chore in turn and Switch depending on the frequency set (1, 2, 4).

    ; Now run through chores and decide if interval criteria met
    $iNextDay = 0
    For $i = 0 To UBound($aChores) - 1
        ; Check required interval
        Switch $aChores[$i][1]
            Case 1 ; Once per week
                ; - If 1 (each week) then we look at each week in turn to see if that chore is already selected
                ; - the "week" element of the $aChores array will have been set if it is
                ; - and if so, remove that chore from that week's list in the $aChoreList array.
                Local $iOffsetDay = 0
                Local $iOffsetWeek = 0
                For $j = 1 To 4

                    If $j = 2 Then $iOffsetWeek += 1
                    If $j = 3 Then $iOffsetWeek += 1
                    If $j = 4 Then $iOffsetWeek += 1
                    $iOffsetDay = 0
                    ; So if chosen in this week
                    If $aChores[$i][$j + 1] And $aChores[$i][$j + 5] = 1 Then
                        ; Remove from the list for this week only
                        ConsoleWrite("Removing " & $aChores[$i][0] & " from List " & $j & @CRLF)
                        $aChoreList[$j] = StringReplace($aChoreList[$j], "|" & $aChores[$i][0] & "|", "|")

                    ElseIf $aChores[$i][$j + 1] And $aChores[$i][$j + 5 - $iOffsetWeek] = 3 Then
                        ;MsgBox('', '', '3 times')
                        If $j >= 1 Then $iOffsetDay += 1
                        $iTimesPerWeek1 = 0
                        $iTimesPerWeek2 = 0
                        $iTimesPerWeek3 = 0
                        $iTimesPerWeek4 = 0
                        For $x = 0 To 6
                            $aDaysTaged = StringSplit($aChores[$i][$j + 5 + $x - $iOffsetWeek + $iOffsetDay], ',', 2)
                            ;_ArrayDisplay($aDaysTaged)
                            Switch $j
                                Case 1
                                    If $aDaysTaged[0] = 1 Then
                                        $iTimesPerWeek1 += 1
                                        $iTimesPerWeek1 = _Clear_Choir($aChores, $aChoreList, 3, $iTimesPerWeek1, $i, $j)
                                    EndIf
                                Case 2
                                    If $aDaysTaged[1] = 1 Then
                                        $iTimesPerWeek2 += 1
                                        $iTimesPerWeek2 = _Clear_Choir($aChores, $aChoreList, 3, $iTimesPerWeek2, $i, $j)
                                    EndIf
                                Case 3
                                    If $aDaysTaged[2] = 1 Then
                                        $iTimesPerWeek3 += 1
                                        $iTimesPerWeek3 = _Clear_Choir($aChores, $aChoreList, 3, $iTimesPerWeek3, $i, $j)
                                    EndIf
                                Case 4
                                    If $aDaysTaged[3] = 1 Then
                                        $iTimesPerWeek4 += 1
                                        $iTimesPerWeek4 = _Clear_Choir($aChores, $aChoreList, 3, $iTimesPerWeek4, $i, $j)
                                    EndIf
                            EndSwitch
                        Next

                        ;_ArrayDisplay($aChores, "Up To Date", Default, 8) ; Display only

                    ElseIf $aChores[$i][$j + 1] And $aChores[$i][$j + 5 - $iOffsetWeek] = 7 Then
                        ;MsgBox('', '7 Times', 'Index? ' & $aChores[$i][$j + 5 - $iOffsetWeek - 4])
                        If $j >= 1 Then $iOffsetDay += 1
                        $iTimesPerWeek1 = 0
                        $iTimesPerWeek2 = 0
                        $iTimesPerWeek3 = 0
                        $iTimesPerWeek4 = 0
                        For $x = 0 To 6
                            $aDaysTaged = StringSplit($aChores[$i][$j + 5 + $x - $iOffsetWeek + $iOffsetDay], ',', 2)
                            ;_ArrayDisplay($aDaysTaged, '7 days taged')
                            Switch $j
                                Case 1
                                    If $aDaysTaged[0] = 1 Then
                                        $iTimesPerWeek1 += 1
                                        $iTimesPerWeek1 = _Clear_Choir($aChores, $aChoreList, 7, $iTimesPerWeek1, $i, $j)
                                    EndIf
                                Case 2
                                    If $aDaysTaged[1] = 1 Then
                                        $iTimesPerWeek2 += 1
                                        $iTimesPerWeek2 = _Clear_Choir($aChores, $aChoreList, 7, $iTimesPerWeek2, $i, $j)
                                    EndIf
                                Case 3
                                    If $aDaysTaged[2] = 1 Then
                                        $iTimesPerWeek3 += 1
                                        $iTimesPerWeek3 = _Clear_Choir($aChores, $aChoreList, 7, $iTimesPerWeek3, $i, $j)

                                    EndIf
                                Case 4
                                    If $aDaysTaged[3] = 1 Then
                                        $iTimesPerWeek4 += 1
                                        $iTimesPerWeek4 = _Clear_Choir($aChores, $aChoreList, 7, $iTimesPerWeek4, $i, $j)
                                    EndIf
                            EndSwitch
                        Next
                        ConsoleWrite($iTimesPerWeek1 & @CRLF)
                        ;_ArrayDisplay($aChores, "Up To Date", Default, 8) ; Display only
                    EndIf
                Next
            Case 2 ; Once every 2 weeks
                ; - If 2 (every 2 weeks) then we need to look at 2-week blocks (1-2 & 3-4)
                ; - and we use 2 loops to do this. The outer loop runs twice with values of 0 and 2, while the inner runs twice from 1 to 2.
                ; Adding them means we get the values 1, 2, 3, 4 which nicely matches the week numbering.
                ; Inside the 2 loops we check both of the "week" elements of the $aChores array for the 2-week block and if the chore is selected,
                ; remove it from both of the lists for those weeks in the $aChoreList array.
                ; Split into 2 x 2-week sections
                For $k = 0 To 2 Step 2
                    ; If chosen in this section
                    $iCount = 0
                    For $j = 1 To 2
                        $iCount += $aChores[$i][$j + $k + 1]
                    Next
                    If $iCount Then

                        $sLists = "1 & 2"
                        If $k Then $sLists = "3 & 4"
                        ;$sLists = (($k) ? ("3 & 4") :("1 & 2"))
                        ConsoleWrite("Removing " & $aChores[$i][0] & " from Lists " & $sLists & @CRLF)

                        ; Remove from both lists for this section
                        For $j = 1 + $k To 2 + $k
                            $aChoreList[$j] = StringReplace($aChoreList[$j], "|" & $aChores[$i][0] & "|", "|")
                        Next
                    EndIf
                Next
            Case 4 ; Once every 4 weeks
                ; - If every 4 weeks then the problem becomes a little simpler
                ; - we need a single loop to check each of the "week" elements of the $aChores array and if the chore is set,
                ; remove it from all of the lists in the $aChoreList array.
                ; If chosen
                $iCount = 0
                For $j = 1 To 4
                    $iCount += $aChores[$i][$j + 1]
                Next
                If $iCount Then
                    ; Remove from all lists
                    ConsoleWrite("Removing " & $aChores[$i][0] & " from ALL Lists" & @CRLF)
                    For $j = 1 To 4
                        $aChoreList[$j] = StringReplace($aChoreList[$j], "|" & $aChores[$i][0] & "|", "|")
                    Next
                EndIf
        EndSwitch
    Next
    ;_ArrayDisplay($aChoreList, "Combo Data Lists", Default, 8) ; Display only


    ; We now have the $aChoreList array filled with 4 lists of the remaining chores for each week.
    ; We run yet another loop to fill each week's combos with their respective list
    ; - not forgetting to add back the currently displayed value and set it as the default.

    ; Now fill combos
    For $i = 0 To 3 ; Weeks
        For $j = 0 To 34 ; Combos
            ; Read combo
            $sSel = GUICtrlRead($cCombo_Start + $j + ($i * 35))
            ; Get data string for this week
            $sData = StringTrimRight($aChoreList[$i + 1], 1)
            ; Add current selection if required
            If $sSel Then
                $sData &= "|" & $sSel
            EndIf
            ; Load combo
            GUICtrlSetData($cCombo_Start + $j + ($i * 35), $sData, $sSel)
        Next
    Next

EndFunc   ;==>_Update_Combos

Func _Clear_Choir(ByRef $aChores, ByRef $aChoreList, $iPerWeek, $iCount, $iIndexI, $iIndexJ)
    ;MsgBox('','$iCount = ' & $iCount,$iPerWeek)
    If $iCount = $iPerWeek Then
        ; Remove from the list for this week only
        ConsoleWrite("Removing " & $aChores[$iIndexI][0] & " from List " & $iIndexJ & @CRLF)
        $aChoreList[$iIndexJ] = StringReplace($aChoreList[$iIndexJ], "|" & $aChores[$iIndexI][0] & "|", "|")
        ;$iTimesPerWeek = 0
        ;MsgBox('', 'perweek', $iCount)
        ;Return $aChoreList
    Else

        ;MsgBox('', 'perweek', $iCount)
        Return $iCount
    EndIf
EndFunc   ;==>_Clear_Choir

 

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

  • Moderators

nitekram,

Can you please explain what you want a little more clearly as I am unsure what the "day" intervals mean. As I read them, most of the chore requirements cannot be satisfied:

Kitchen:          1 [every week]     7 [7 day interval] ; This I understand if we decide it will always happen on the same day
Master Bed Room:  1 [every week]     3 [3 day interval] ; But how can there be a 3 day interval if the chore only happens once a week?
Front Bed Room:   2 [every 2 weeks]  1 [1 day interval] ; Again how can these 2 requirements be satisfied?
Back Bed Room:    2 [every 2 weeks]  1 [1 day interval] ; Same question
Bathroom Full:    1 [every week]     1 [1 day interval] ; And again

Would you prefer to go with just the day intervals? If that was the sole criterion we could simply remove the chosen chore from the lists of the following X days.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

My idea was to make certain chores to have to be performed every week as well as more than once per week. I am not saying I am going to clean the kitchen 7 days a week, as I would be hard pressed to clean it once a week lol. But my idea was that this could be used for more than just chores (and therefore may want to do every week and more than once per week) ...as a way of a structure of your time (we all need structure lol). It could be: a work out schedule, monthly menu, task list, chore list...what have you.

Maybe my wording is off on the parameter for the array, rather than interval, I should have used TimesPerWeek

 

I do have some questions about getting the right algorithm for both, my changes, as well as reading the check boxes. I will be getting to the check boxes later (after a little clean up of the code I am testing), but looking at my most resent code (post), trying to think differently than my self and more like you, what do you see as wrong or something that makes it clearer, faster, or better?

 

EDIT
As for the times per week, I believe that is working correctly...my idea was before it gets to far out of my head, what changes could be made that would make it better, as I spent quite a lot of time, trying to get it to work.

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

  • Moderators

nitekram,

After a period of reflection (and head-scratching) I am afraid that I am not able to offer any sensible comments on the code you posted for the following reasons:

 - 1. Your additional code within the script is completely uncommented.  If you want people to try and fathom out a better way to do what you are doing, the least you can do is explain what the code is currently intended to do.

- 2. There is a massive amount of "checkbox" code which you tell me is not yet working as you want. And I am supposed to work out what is going on around all that?

- 3. You appear to have decided to completely change the requirements of the script to depend on a fixed interval between events rather than merely happening once in a 1/2/4 week period, which has rendered the underlying algorithm I had developed completely useless.

If you wish, I am prepared to think about how to develop a new algorithm to work with a fixed interval between events (although I am struggling to see how to do it at the moment) but, as I said above, for the reasons stated I feel I cannot offer any comments on your current code. 

Sorry if this appears harsh, but I have many other demands on my time and trying to massage an unsuited algorithm to match a new requirement is a sure way to waste what time I am prepared to offer.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I am sorry for posting the code the way it was...I was excited to see how to change my code, to sort of match your example. I have removed, much of the comments (bloated), and removed the combo boxes, as I am still working on that part.

So what I have attempted to do, is take you existing example and add to it - though I am not sure it was the best way, or the only way. I did this more or less to learn from your code, and to allow the script to be more than just a chore keeper - based on pulling in a different, but same type of array, with other items.

The chore array, includes the name, the first parameter for how many times a month (every week, every other week, once a month), then there are 4 indexes for keeping track of entries for those. I added another parameter (index 6) that will allow the chore to show up more than once per week. The parameters are, 1 time a week, 3 times a week, and 7 times a week (though I may change that to 5 days, as you will never see the chore disappear otherwise). I then have an index for each of the day of the week Sun-Sat

All the chores right now, except the first two, Kitchen & Master Bed Room, are all set to only happen once each week. But a chore or a task, could happen every week and more than once per week - at least that was my thinking (after using your example)

The code works as you created it. The part I added, would be how many times a week is it performed. I am not used to dummy controls and linking them up to an array, is where I am lost. Within an array, I could have the control id, along with other data, but I am really interested in learning about both dummy controls and the all powerful 'Algorithm' - as I believe this will get me to the next step in programming.

The code as it sits works...I am only looking for direction on how it could be done better or faster, or if I made it too difficult to read - I would say the last one is TRUE, because of your last post - again sorry.

So without further ado:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>

#include <Array.au3>

;         Chore([22][6]),           interval (1, 2, 4 weeks),   Count in week 1,2,3,4   , how many times per week (1, 3, 7, days),  count in days 1,2,3,4,5,6,7
Global $aChoresBase[22][14] = [ _
        ['Kitchen', 1, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0], _
        ['Master Bed Room', 1, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0], _
        ['Front Bed Room', 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Back Bed Room', 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Bathroom Full', 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Bathroom Half', 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Living Room', 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Dining Bar', 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Dining Porch', 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Basement', 4, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Garage', 4, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Laundry Room', 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Lawn (Cutting)', 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Storage', 4, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Porch', 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Closed Porch', 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Weed Pulling', 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Misc1', 4, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Misc2', 4, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Misc3', 4, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Misc4', 4, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], _
        ['Misc5', 4, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]]

;_ArrayDisplay($aChoresBase, "Original", Default, 8) ; Display only

; create a new value for each of the last seven indexes in the array for chores...to keep track of how many are showing up in each week
If 1 = 1 Then
    ; Set default string for days of the week
    For $x = 0 To UBound($aChoresBase) - 1
        For $y = 7 To 13
            $aChoresBase[$x][$y] = '0,0,0,0'
        Next
    Next


EndIf

;_ArrayDisplay($aChoresBase, "Original", Default, 8) ; Display only

; Create combo list
$sChoreListBase = ""
For $i = 0 To UBound($aChoresBase) - 1
    $sChoreListBase &= "|" & $aChoresBase[$i][0]
Next

Global $cCombo_Start, $cCheckBox_Start, $ahCheckBox

CreateSchedule()

Func CreateSchedule()

    Local $hMainGui = GUICreate('Chore List', 1200, 540)

    ; Create labels
    Local $iWeekSpacing = 125, $iWeekOffset = 90 ; 125, 90 ( I changed the default settings to allow for check boxes
    For $i = 1 To 4
        GUICtrlCreateLabel('Week ' & $i, 10, ($i * $iWeekSpacing) - $iWeekOffset)
    Next
    Local $iDaySpacing = 155, $iDayOffset = 45 ; 155, 45
    Local $aDay[8] = ["", 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
    For $i = 1 To 7
        GUICtrlCreateLabel($aDay[$i], $iDaySpacing * ($i) - $iDayOffset, 10, 125, 20, $SS_CENTER)
    Next

    ; Create combos
    $cCombo_Start = GUICtrlCreateDummy() + 1 ; ControlID of first combo
    Local $iComboOffset = 21, $iChoresPerDay = 5, $iComboMoveLeft = 0 ;-35

    For $i = 1 To 4 ; Weeks
        $iY_Base = ($i * $iWeekSpacing) - $iWeekOffset
        For $j = 1 To 7 ; Days
            $iX = ($iDaySpacing * $j) - $iDayOffset + $iComboMoveLeft
            For $k = 0 To $iChoresPerDay - 1 ; Chores
                $iY = $iY_Base + ($iComboOffset * $k)
                GUICtrlCreateCombo("", $iX, $iY, 125, 20)
                GUICtrlSetData(-1, $sChoreListBase)
            Next
        Next
    Next

    $cCombo_End = GUICtrlCreateDummy() - 1 ; ControlID of last combo

    GUISetState()
    Local $iCount_Blink = 0
    While 1
        $iMsg = GUIGetMsg()
        Switch $iMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $cCombo_Start To $cCombo_End ; Combo actioned
                _Update_Combos()
        EndSwitch

    WEnd


EndFunc   ;==>CreateSchedule
;
;
Func _Update_Combos()
    ; First we create a copy of the $aChores array so we can see what is and is not set this time around.
    Local $aChores = $aChoresBase
    Local $iTimesPerWeek1 = 0, $iTimesPerWeek2 = 0, $iTimesPerWeek3 = 0, $iTimesPerWeek4 = 0 ; created to keep trak of count of chore per week
    Local $aDaysTaged
    Local $iNextDay = 0 ; used to move through each day of the week
    Local $aWeeks
    Local $iOffsetChoreWeek = 0
    For $i = 0 To 3 ; Weeks
        $iNextDay = 0
        ;
        If $i >= 1 Then $iOffsetChoreWeek += 1
        ;
        For $j = 0 To 34 ; Combos
            ; Used for both the next day of the week and also to offset the array index with $iOffsetChoreWeek
            If Mod($j, 5) = 0 And $j <> 0 Then $iNextDay += 1 ; after each 5 tasks, move to the next day

            ; Read combo setting - ControlID calculated
            $sSel = GUICtrlRead($cCombo_Start + $j + ($i * 35))

            If $sSel Then
                ; Find index of selected chore in the array
                $iIndex = _ArraySearch($aChores, $sSel)
                ; Set for correct week
                $aChores[$iIndex][$i + 2] += 1 ; Set week true
                ;
                ; change the value for each day that has the chore listed - so set day true for that week
                $aWeeks = StringSplit($aChores[$iIndex][$i + 7 + $iNextDay - $iOffsetChoreWeek], ',', 2)
                ;
                Switch $i
                    Case 0
                        $aWeeks[0] += 1
                    Case 1
                        $aWeeks[1] += 1
                    Case 2
                        $aWeeks[2] += 1
                    Case 3
                        $aWeeks[3] += 1
                EndSwitch

                $aChores[$iIndex][$i + 7 + $iNextDay - $iOffsetChoreWeek] = _ArrayToString($aWeeks, ',') ; Set string for each day of the week

            EndIf
        Next
    Next
    ;_ArrayDisplay($aChores, "Up To Date", Default, 8) ; Display only

    ; Copy base combo list - one for each week
    Local $aChoreList[5] = ["", $sChoreListBase & "|", $sChoreListBase & "|", $sChoreListBase & "|", $sChoreListBase & "|"]

    $iNextDay = 0
    For $i = 0 To UBound($aChores) - 1
        ; Check required interval
        Switch $aChores[$i][1]
            Case 1 ; Once per week
                Local $iOffsetDay = 0
                Local $iOffsetWeek = 0

                For $j = 1 To 4
                    If $j>= 2 Then $iOffsetWeek += 1 ; offset - in order to locate the index of the chore array for the right day, for the week in question
                    $iOffsetDay = 0
                    ; So if chosen in this week
                    If $aChores[$i][$j + 1] And $aChores[$i][$j + 5] = 1 Then ; if the chore happesn every a week, but only 1 time for that week
                        ; Remove from the list for this week only
                        ConsoleWrite("Removing " & $aChores[$i][0] & " from List " & $j & @CRLF)
                        $aChoreList[$j] = StringReplace($aChoreList[$j], "|" & $aChores[$i][0] & "|", "|")

                    ElseIf $aChores[$i][$j + 1] And $aChores[$i][$j + 5 - $iOffsetWeek] = 3 Then ; if the chore happesn every a week, but can happen 3 times during that week
                        ;MsgBox('', '', '3 times')
                        If $j >= 1 Then $iOffsetDay += 1
                        $iTimesPerWeek1 = 0
                        $iTimesPerWeek2 = 0
                        $iTimesPerWeek3 = 0
                        $iTimesPerWeek4 = 0
                        For $x = 0 To 6
                            $aDaysTaged = StringSplit($aChores[$i][$j + 5 + $x - $iOffsetWeek + $iOffsetDay], ',', 2) ; split the index, devide the day, so it shows 4 weeks, 0,0,0,0
                            ;_ArrayDisplay($aDaysTaged)
                            ;
                            ; if the chore shows up for a day, mark the week it happens (first week, 1,0,0,0 - second week, 0.1.0.0 - ect.)
                            Switch $j
                                Case 1
                                    If $aDaysTaged[0] = 1 Then ; 1,0,0,0
                                        $iTimesPerWeek1 += 1
                                        $iTimesPerWeek1 = _Clear_Choir($aChores, $aChoreList, 3, $iTimesPerWeek1, $i, $j)
                                    EndIf
                                Case 2
                                    If $aDaysTaged[1] = 1 Then ; 0,1,0,0
                                        $iTimesPerWeek2 += 1
                                        $iTimesPerWeek2 = _Clear_Choir($aChores, $aChoreList, 3, $iTimesPerWeek2, $i, $j)
                                    EndIf
                                Case 3
                                    If $aDaysTaged[2] = 1 Then ; 0,0,1,0
                                        $iTimesPerWeek3 += 1
                                        $iTimesPerWeek3 = _Clear_Choir($aChores, $aChoreList, 3, $iTimesPerWeek3, $i, $j)
                                    EndIf
                                Case 4
                                    If $aDaysTaged[3] = 1 Then ; 0,0,0,1
                                        $iTimesPerWeek4 += 1
                                        $iTimesPerWeek4 = _Clear_Choir($aChores, $aChoreList, 3, $iTimesPerWeek4, $i, $j)
                                    EndIf
                            EndSwitch
                        Next

                        ;_ArrayDisplay($aChores, "Up To Date", Default, 8) ; Display only

                    ElseIf $aChores[$i][$j + 1] And $aChores[$i][$j + 5 - $iOffsetWeek] = 7 Then ; if the chore happesn every a week, but can happen 7 times during that week
                        ;MsgBox('', '7 Times', 'Index? ' & $aChores[$i][$j + 5 - $iOffsetWeek - 4])
                        If $j >= 1 Then $iOffsetDay += 1
                        $iTimesPerWeek1 = 0
                        $iTimesPerWeek2 = 0
                        $iTimesPerWeek3 = 0
                        $iTimesPerWeek4 = 0
                        For $x = 0 To 6
                            $aDaysTaged = StringSplit($aChores[$i][$j + 5 + $x - $iOffsetWeek + $iOffsetDay], ',', 2)
                            ;_ArrayDisplay($aDaysTaged, '7 days taged')
                            ;
                            ; if the chore shows up for a day, mark the week it happens (first week, 1,0,0,0 - second week, 0,1,0,0 - ect.)
                            Switch $j
                                Case 1
                                    If $aDaysTaged[0] = 1 Then ; 1,0,0,0
                                        $iTimesPerWeek1 += 1
                                        $iTimesPerWeek1 = _Clear_Choir($aChores, $aChoreList, 7, $iTimesPerWeek1, $i, $j)
                                    EndIf
                                Case 2
                                    If $aDaysTaged[1] = 1 Then ; 0,1,0,0
                                        $iTimesPerWeek2 += 1
                                        $iTimesPerWeek2 = _Clear_Choir($aChores, $aChoreList, 7, $iTimesPerWeek2, $i, $j)
                                    EndIf
                                Case 3
                                    If $aDaysTaged[2] = 1 Then ; 0,0,1,0
                                        $iTimesPerWeek3 += 1
                                        $iTimesPerWeek3 = _Clear_Choir($aChores, $aChoreList, 7, $iTimesPerWeek3, $i, $j)

                                    EndIf
                                Case 4
                                    If $aDaysTaged[3] = 1 Then ; 0,0,0,1
                                        $iTimesPerWeek4 += 1
                                        $iTimesPerWeek4 = _Clear_Choir($aChores, $aChoreList, 7, $iTimesPerWeek4, $i, $j)
                                    EndIf
                            EndSwitch
                        Next
                        ConsoleWrite($iTimesPerWeek1 & @CRLF)
                        ;_ArrayDisplay($aChores, "Up To Date", Default, 8) ; Display only
                    EndIf
                Next
            Case 2 ; Once every 2 weeks
                For $k = 0 To 2 Step 2
                    ; If chosen in this section
                    $iCount = 0
                    For $j = 1 To 2
                        $iCount += $aChores[$i][$j + $k + 1]
                    Next
                    If $iCount Then

                        $sLists = "1 & 2"
                        If $k Then $sLists = "3 & 4"
                        ;$sLists = (($k) ? ("3 & 4") :("1 & 2"))
                        ConsoleWrite("Removing " & $aChores[$i][0] & " from Lists " & $sLists & @CRLF)

                        ; Remove from both lists for this section
                        For $j = 1 + $k To 2 + $k
                            $aChoreList[$j] = StringReplace($aChoreList[$j], "|" & $aChores[$i][0] & "|", "|")
                        Next
                    EndIf
                Next
            Case 4 ; Once every 4 weeks
                $iCount = 0
                For $j = 1 To 4
                    $iCount += $aChores[$i][$j + 1]
                Next
                If $iCount Then
                    ; Remove from all lists
                    ConsoleWrite("Removing " & $aChores[$i][0] & " from ALL Lists" & @CRLF)
                    For $j = 1 To 4
                        $aChoreList[$j] = StringReplace($aChoreList[$j], "|" & $aChores[$i][0] & "|", "|")
                    Next
                EndIf
        EndSwitch
    Next
    ;_ArrayDisplay($aChoreList, "Combo Data Lists", Default, 8) ; Display only


    ; Now fill combos
    For $i = 0 To 3 ; Weeks
        For $j = 0 To 34 ; Combos
            ; Read combo
            $sSel = GUICtrlRead($cCombo_Start + $j + ($i * 35))
            ; Get data string for this week
            $sData = StringTrimRight($aChoreList[$i + 1], 1)
            ; Add current selection if required
            If $sSel Then
                $sData &= "|" & $sSel
            EndIf
            ; Load combo
            GUICtrlSetData($cCombo_Start + $j + ($i * 35), $sData, $sSel)
        Next
    Next

EndFunc   ;==>_Update_Combos

Func _Clear_Choir(ByRef $aChores, ByRef $aChoreList, $iPerWeek, $iCount, $iIndexI, $iIndexJ)
    ; based on $iPerWeek, this function will remove the chore for that week
    ; so if the chore happens every week, and 3 times each week, then once 3 times have been chosen from the combo, it will be removed for that week
    ;MsgBox('','$iCount = ' & $iCount,$iPerWeek)
    If $iCount = $iPerWeek Then
        ; Remove from the list for this week only
        ConsoleWrite("Removing " & $aChores[$iIndexI][0] & " from List " & $iIndexJ & @CRLF)
        $aChoreList[$iIndexJ] = StringReplace($aChoreList[$iIndexJ], "|" & $aChores[$iIndexI][0] & "|", "|")
    Else
        Return $iCount
    EndIf
EndFunc   ;==>_Clear_Choir

 

Edited by nitekram
grammar

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

  • Moderators

nitekram,

No need to apologise - I was just explaining why I felt I could not offer much help.  Not that easy when you cannot understand what is going on!

I return to my earlier comment about revisiting data storage if it has become difficult to code with it in its current form. I have done just that and managed to keep exactly the same algorithm as before while allowing the selection of chores more than once a week.  If you look at the array below you will see that there is a new column "Times weekly if weekly" which sets the maximum times that chore can be selected in the week. Doing this allows us to maintain the existing "every 2/4 weeks" selections with no code changes - only the "by week" chores need slightly amended code to check if the chore has already been selected the required number of times. And in fact this code is not very different at all - only 1 line has been changed (if you ignore comments and some minor reorganisation).  Not a bad result, even if I say it myself.

I also wondered if you wanted to prevent the same chore being selected more than once a day, so I have rewritten the "; Now fill combos" section to do this. The combo filling is now done in daily, rather then weekly, blocks. In addition to those chores removed on a weekly basis, the combos in each day block also have the chores already selected that day removed from their lists so that they cannot be selected again. If you do not wish this added functionality, then just replace that section by the code in the script I originally posted.

So after all that explanation, here is the script (there are one or two other small additions, but I will let you play "spot the difference" to find them):

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>

#include <Array.au3>

;       Chore([22][7]),     Interval (1, 2, 4 weeks),   Times weekly if weekly, Count in week 1,2,3,4
Global $aChoresBase[22][7] = [ _
        ['Kitchen',         1,                          3,                      0, 0, 0, 0], _
        ['Master Bed Room', 1,                          3,                      0, 0, 0, 0], _
        ['Front Bed Room',  2,                          0,                      0, 0, 0, 0], _
        ['Back Bed Room',   2,                          0,                      0, 0, 0, 0], _
        ['Bathroom Full',   1,                          2,                      0, 0, 0, 0], _
        ['Bathroom Half',   2,                          2,                      0, 0, 0, 0], _
        ['Living Room',     1,                          1,                      0, 0, 0, 0], _
        ['Dining Bar',      1,                          2,                      0, 0, 0, 0], _
        ['Dining Porch',    2,                          0,                      0, 0, 0, 0], _
        ['Basement',        4,                          0,                      0, 0, 0, 0], _
        ['Garage',          4,                          0,                      0, 0, 0, 0], _
        ['Laundry Room',    2,                          0,                      0, 0, 0, 0], _
        ['Lawn (Cutting)',  2,                          0,                      0, 0, 0, 0], _
        ['Storage',         4,                          0,                      0, 0, 0, 0], _
        ['Porch',           2,                          0,                      0, 0, 0, 0], _
        ['Closed Porch',    2,                          0,                      0, 0, 0, 0], _
        ['Weed Pulling',    2,                          0,                      0, 0, 0, 0], _
        ['Misc1',           4,                          0,                      0, 0, 0, 0], _
        ['Misc2',           4,                          0,                      0, 0, 0, 0], _
        ['Misc3',           4,                          0,                      0, 0, 0, 0], _
        ['Misc4',           4,                          0,                      0, 0, 0, 0], _
        ['Misc5',           4,                          0,                      0, 0, 0, 0]]

;_ArrayDisplay($aChoresBase, "Original", Default, 8) ; Display only

; Create combo list
$sChoreListBase = ""
For $i = 0 To UBound($aChoresBase) - 1
    $sChoreListBase &= "|" & $aChoresBase[$i][0]
Next

Global $hMainGui, $cCombo_Start, $iChoresPerDay = 5 ; A few more Global variables

CreateSchedule()

Func CreateSchedule()

    SplashTextOn("Inititalising", "Please be patient") ; I kept wondering if it was running!

   $hMainGui = GUICreate('Chore List', 1200, 540)

    ; Create labels
    Local $iWeekSpacing = 125, $iWeekOffset = 90 ; 125, 90 ( I changed the default settings to allow for check boxes
    For $i = 1 To 4
        GUICtrlCreateLabel('Week ' & $i, 10, ($i * $iWeekSpacing) - $iWeekOffset)
    Next
    Local $iDaySpacing = 155, $iDayOffset = 45 ; 155, 45
    Local $aDay[8] = ["", 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
    For $i = 1 To 7
        GUICtrlCreateLabel($aDay[$i], $iDaySpacing * ($i) - $iDayOffset, 10, 125, 20, $SS_CENTER)
    Next

    ; Create combos
    $cCombo_Start = GUICtrlCreateDummy() + 1 ; ControlID of first combo
    Local $iComboOffset = 21, $iComboMoveLeft = 0 ;-35

    For $i = 1 To 4 ; Weeks
        $iY_Base = ($i * $iWeekSpacing) - $iWeekOffset
        For $j = 1 To 7 ; Days
            $iX = ($iDaySpacing * $j) - $iDayOffset + $iComboMoveLeft
            For $k = 0 To $iChoresPerDay - 1 ; Chores
                $iY = $iY_Base + ($iComboOffset * $k)
                GUICtrlCreateCombo("", $iX, $iY, 125, 20)
                GUICtrlSetData(-1, $sChoreListBase)
            Next
        Next
    Next

    $cCombo_End = GUICtrlCreateDummy() - 1 ; ControlID of last combo

    GUISetState()

    SplashOff()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
            Case $cCombo_Start To $cCombo_End ; Combo actioned
                _Update_Combos()
        EndSwitch

    WEnd

EndFunc   ;==>CreateSchedule

Func _Update_Combos()

    ; Disable GUI until function terminates - just prevents selecting another combo before reloading has finished
    GUISetState(@SW_DISABLE, $hMainGui)

    ; First we create a copy of the $aChores array so we can see what is and is not set this time around.
    Local $aChores = $aChoresBase
    For $i = 0 To 3 ; Weeks
        For $j = 0 To 34 ; Combos
            $sSel = GUICtrlRead($cCombo_Start + $j + ($i * 35))

            If $sSel Then
                ; Find index of selected chore in the array
                $iIndex = _ArraySearch($aChores, $sSel)
                ; Set for correct week
                $aChores[$iIndex][$i + 3] += 1 ; Set week true
            EndIf
        Next
    Next
    ;_ArrayDisplay($aChores, "Up To Date", Default, 8) ; Display only

    ; Copy base combo list - one for each week
    Local $aChoreList[5] = ["", $sChoreListBase & "|", $sChoreListBase & "|", $sChoreListBase & "|", $sChoreListBase & "|"]

    For $i = 0 To UBound($aChores) - 1
        ; Check required interval
        Switch $aChores[$i][1]
            Case 1 ; Weekly or more
                For $j = 1 To 4
                    ; Get current count for this chore in this week
                    $iCurrent_Count = $aChores[$i][$j + 2]
                    ; Compare to max required per week
                    If $iCurrent_Count = $aChores[$i][2] Then
                        ; Remove from the list for this week only
                        $aChoreList[$j] = StringReplace($aChoreList[$j], "|" & $aChores[$i][0] & "|", "|")
                    EndIf
                Next
            Case 2 ; Once every 2 weeks
                For $k = 0 To 2 Step 2
                    ; If chosen in this section
                    $iCount = 0
                    For $j = 1 To 2
                        $iCount += $aChores[$i][$j + $k + 2]
                    Next
                    If $iCount Then
                        $sLists = "1 & 2"
                        If $k Then $sLists = "3 & 4"
                        ; Remove from both lists for this section
                        For $j = 1 + $k To 2 + $k
                            $aChoreList[$j] = StringReplace($aChoreList[$j], "|" & $aChores[$i][0] & "|", "|")
                        Next
                    EndIf
                Next
            Case 4 ; Once every 4 weeks
                $iCount = 0
                For $j = 1 To 4
                    $iCount += $aChores[$i][$j + 2]
                Next
                If $iCount Then
                    ; Remove from all lists
                    For $j = 1 To 4
                        $aChoreList[$j] = StringReplace($aChoreList[$j], "|" & $aChores[$i][0] & "|", "|")
                    Next
                EndIf
        EndSwitch
    Next
    ;_ArrayDisplay($aChoreList, "Combo Data Lists", Default, 8) ; Display only

    ; Now fill combos - allowing each chore to be selected only once per day
    For $i = 0 To 3 ; Weeks
        For $j = 0 To 34 Step $iChoresPerDay ; Combo blocks by day
            ; For each day get data string for this week
            $sDataDay = $aChoreList[$i + 1]
            For $k = 0 To $iChoresPerDay - 1 ; Combos in block
                ; Read combos
                $sSel = GUICtrlRead($cCombo_Start + $k + $j + ($i * 35))
                ; Remove currently selected items from day list
                $sDataDay = StringReplace($sDataDay, "|" & $sSel & "|", "|")
            Next
            ; Now add day list to each combo, re-adding current selection if there is one
            For $k = 0 To $iChoresPerDay - 1
                $sSel = GUICtrlRead($cCombo_Start + $k + $j + ($i * 35))
                $sDataCombo = StringTrimRight($sDataDay, 1)
                If $sSel Then
                    $sDataCombo &= "|" & $sSel
                EndIf
                ; Load combo
                GUICtrlSetData($cCombo_Start + $k + $j + ($i * 35), $sDataCombo, $sSel)
            Next
        Next
    Next

    ; Re-enable GUI
    GUISetState(@SW_ENABLE, $hMainGui)

EndFunc   ;==>_Update_Combos

Again, please ask if you have any questions on what I have done or why I have done it - and certainly tell me if the code does not do what you want.

Are you looking to save and reload the data at any time? Or to populate the basic chore array with the required chores and their required interval? That would be a fun little project.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

First...I need to know how long it took you to change your code, as it appears from what I see - you planned on it, meaning that your new change looks like it was planned from the beginning, how the += was already there for counting the weeks.

This sort of reminds me of when I learned to play chess...I would play over the great games, and wonder why they made the move they did, only to find out why, 7 to 10 moves later. I am not going to give up...I am going to get this someday. In the mean time, I am glad that there are people like you and others here, that will show novice coders what it is like to really program.

I am sure I will be back soon, as I am still trying to figure out the check boxes, but maybe after reviewing your changes, I will be able to figure out the algorithm.

Thanks again...

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

  • Moderators

nitekram,

It was entirely fortuitous that the data structure I coded for the earlier algorithm lent itself to managing the new "several times a week" change. I was very pleased when I realised how easy it would be to modify the code - and I was also very aware of how lucky I was to have created the data structure in that way originally. So please do not go away thinking that I am some kind of prescient genius - I assure you that it was pure chance.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Too late - you are already my hero lol

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

  • Moderators

nitekram,

Here is that version I promised which saves, reloads and modifies - filled in an evening with nothing on the TV:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <AutoItConstants.au3>
#include <StaticConstants.au3>
#include <GuiComboBox.au3>
#include <Array.au3>

Global $aLoad_Data, $aItemBase, $hMainGui, $cCombo_Start, $iItemsPerDay, $sItemListBase



If $CmdLine[0] Then
    $sFile = $CmdLine[1]
    $aLoad_Data = _Load_State(@ScriptDir & "\" & $sFile)
Else
    Switch MsgBox($MB_SYSTEMMODAL + $MB_YESNOCANCEL, "Load", "Load an existing file?")
        Case $IDYES
            $aLoad_Data = _Load_State()
            If @error Then Exit
        Case $IDNO
            $aLoad_Data = _Define_New()
            If @error Then Exit
        Case Else
            ; Exit
            $aLoad_Data = _Load_Sim() ; Just to use the currently defined data for testing
    EndSwitch
EndIf

_Create_GUI()

Func _Create_GUI()

    SplashTextOn("Inititalising", "Please be patient", 300, 100)

    Local $iWeekSpacing = (20 * $iItemsPerDay) + 25, $iWeekOffset = $iWeekSpacing - 40
    Local $iDaySpacing = 155, $iDayOffset = 45, $iComboOffset = 21

    $hMainGui = GUICreate('Item Schedule', 1200, (4 * $iWeekSpacing) + 60)

    $mFile = GUICtrlCreateMenu("&File")
    $mFileNew = GUICtrlCreateMenuItem("&New", $mFile)
    $mFileLoad = GUICtrlCreateMenuItem("&Load", $mFile)
    $mFileSave = GUICtrlCreateMenuItem("&Save", $mFile)
    GUICtrlCreateMenuItem("", $mFile)
    $mFileExit = GUICtrlCreateMenuItem("E&xit", $mFile)

    ; Create labels
    For $i = 1 To 4
        GUICtrlCreateLabel('Week ' & $i, 10, ($i * $iWeekSpacing) - $iWeekOffset)
    Next
    Local $aDay[8] = ["", 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
    For $i = 1 To 7
        GUICtrlCreateLabel($aDay[$i], $iDaySpacing * ($i) - $iDayOffset, 10, 125, 20, $SS_CENTER)
    Next

    ; Create combos
    $cCombo_Start = GUICtrlCreateDummy() + 1
    $iIndex = 0
    For $i = 1 To 4 ; Weeks
        $iY_Base = ($i * $iWeekSpacing) - $iWeekOffset
        For $j = 1 To 7 ; Days
            $iX = ($iDaySpacing * $j) - $iDayOffset
            For $k = 0 To $iItemsPerDay - 1 ; Items
                $iY = $iY_Base + ($iComboOffset * $k)
                GUICtrlCreateCombo("", $iX, $iY, 125, 20, $CBS_DROPDOWNLIST)
                GUICtrlSetData(-1, $aLoad_Data[$iIndex][0], $aLoad_Data[$iIndex][1])
                $iIndex += 1
            Next
        Next
    Next
    $cCombo_End = GUICtrlCreateDummy() - 1

    SplashOff()

    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $mFileExit
                Exit
            Case $cCombo_Start To $cCombo_End ; Combo actioned
                _Update_Combos()
            Case $mFileNew
                $aLoad_Data = _Define_New()
                If Not @error Then
                    GUIDelete($hMainGui)
                    _Create_GUI()
                EndIf
            Case $mFileLoad
                $aLoad_Data = _Load_State()
                GUIDelete($hMainGui)
                _Create_GUI()
            Case $mFileSave
                _Save_State()
                If @error Then
                    MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "Error", "Save failed")
                EndIf
        EndSwitch

    WEnd

EndFunc   ;==>_Create_GUI

Func _Load_State($sFile = "")

    If Not $sFile Then
        $sFile = FileOpenDialog("Open", @ScriptDir, "All (*.*)")
    EndIf

    If $sFile Then
        ; Read data from saved file
        $iItemsPerDay = IniRead($sFile, "Base", "ItemsPerDay", "Error")
        If @error Then Return SetError(1, 0, "")
        $sItemListBase = IniRead($sFile, "Base", "ItemList", "Error")
        If @error Then Return SetError(2, 0, "")
        $sBaseArray = IniRead($sFile, "Base", "BaseArray", "Error")
        If @error Then Return SetError(3, 0, "")

        ; Create required base array
        Local $aLines = StringSplit($sBaseArray, "|")
        Global $aItemBase[$aLines[0]][7]
        For $i = 1 To $aLines[0]
            $aSplit = StringSplit($aLines[$i], ",")
            $aItemBase[$i - 1][0] = $aSplit[1]
            $aItemBase[$i - 1][1] = $aSplit[2]
            $aItemBase[$i - 1][2] = $aSplit[3]
            For $j = 3 To 6
                $aItemBase[$i - 1][$j] = 0
            Next
        Next

        ; Create array holding individual combo data
        $iTotal = 4 * 7 * $iItemsPerDay
        Local $aList[$iTotal][2]
        For $i = 0 To $iTotal - 1
            $sVal = IniRead($sFile, "Combos", $i, "Error")
            If @error Then
                Return SetError(4, 0, "")
            Else
                $aSplit = StringSplit($sVal, ",")
                $aList[$i][0] = $aSplit[1]
                $aList[$i][1] = $aSplit[2]
            EndIf
        Next
        Return $aList
    Else
        Return SetError(1, 0, "")
    EndIf

EndFunc   ;==>_Load_State

Func _Save_State()

    $sFile = FileSaveDialog("Save As", @ScriptDir, "All (*.*)")
    If @error Then Return SetError(1, 0, "")

    ; Write data
    IniWrite($sFile, "Base", "ItemsPerDay", $iItemsPerDay)
    IniWrite($sFile, "Base", "ItemList", $sItemListBase)
    For $j = 0 To (4 * 7 * $iItemsPerDay) - 1
        IniWrite($sFile, "Combos", $j, _GUICtrlComboBox_GetList($cCombo_Start + $j) & "," & GUICtrlRead($cCombo_Start + $j))
    Next
    $sBaseArray = ""
    For $i = 0 To UBound($aItemBase, $UBOUND_ROWS) - 1
        For $j = 0 To 2
            $sBaseArray &= $aItemBase[$i][$j] & ","
        Next
        $sBaseArray = StringTrimRight($sBaseArray, 1) & "|"
    Next
    IniWrite($sFile, "Base", "BaseArray", StringTrimRight($sBaseArray, 1))

EndFunc   ;==>_Save_State

Func _Define_New()


    ; Create default interval list
    Local $sInterval = "|Every day|6 times a week|5 times a week|4 times a week|3 times a week|Twice a week|Once a week|Every 2 weeks|Every 4 weeks"
    Local $aList = "", $sDefault = "Every day"

    ; Create GUI
    $hNewGUI = GUICreate("Create New List", 430, 680, Default, Default, Default, Default, $hMainGui)

    $cInput_Start = GUICtrlCreateDummy() + 1
    For $i = 0 To 24
        GUICtrlCreateInput("", 10, 10 + (25 * $i), 200, 20)
        GUICtrlCreateCombo("", 220, 10 + (25 * $i), 200, 20, $CBS_DROPDOWNLIST)
        GUICtrlSetData(-1, $sInterval, $sDefault)
    Next
    $cPerDay = GUICtrlCreateCombo("", 10, 645, 100, 20, $CBS_DROPDOWNLIST)
    GUICtrlSetData($cPerDay, "1|2|3|4|5")
    GUICtrlCreateLabel("Items per day", 120, 650, 100, 20)
    $cAmend = GUICtrlCreateButton("Amend", 220, 640, 60, 30)
    $cAccept = GUICtrlCreateButton("Accept", 290, 640, 60, 30)
    $cCancel = GUICtrlCreateButton("Cancel", 360, 640, 60, 30)

    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $cCancel
                GUIDelete($hNewGUI)
                Return SetError(1, 0, "")
            Case $cAmend ; Load existing file to amend data
                $sFile = FileOpenDialog("Open", @ScriptDir, "All (*.*)")
                If $sFile Then
                    ; Check load was correct
                    $bError = False
                    $iLocalItemsPerDay = IniRead($sFile, "Base", "ItemsPerDay", "Error")
                    If @error Then $bError = True
                    $sLocalBaseArray = IniRead($sFile, "Base", "BaseArray", "Error")
                    If @error Then $bError = True
                    If Not $bError Then
                        ; Fill GUI with loaded data
                        GUICtrlSetData($cPerDay, "1|2|3|4|5", $iLocalItemsPerDay)
                        Local $aLines = StringSplit($sLocalBaseArray, "|")
                        For $i = 1 To $aLines[0]
                            $aSplit = StringSplit($aLines[$i], ",")
                            GUICtrlSetData($cInput_Start + ($i - 1) * 2, $aSplit[1])
                            Switch $aSplit[2]
                                Case 4
                                    GUICtrlSetData($cInput_Start + 1 + ($i - 1) * 2, $sInterval, "Every 4 weeks")
                                Case 2
                                    GUICtrlSetData($cInput_Start + 1 + ($i - 1) * 2, $sInterval, "Every 2 weeks")
                                Case 1
                                    Switch $aSplit[3]
                                        Case 7
                                            GUICtrlSetData($cInput_Start + 1 + ($i - 1) * 2, $sInterval, "Every day")
                                        Case 6
                                            GUICtrlSetData($cInput_Start + 1 + ($i - 1) * 2, $sInterval, "6 times a week")
                                        Case 5
                                            GUICtrlSetData($cInput_Start + 1 + ($i - 1) * 2, $sInterval, "5 times a week")
                                        Case 4
                                            GUICtrlSetData($cInput_Start + 1 + ($i - 1) * 2, $sInterval, "4 times a week")
                                        Case 3
                                            GUICtrlSetData($cInput_Start + 1 + ($i - 1) * 2, $sInterval, "3 times a week")
                                        Case 2
                                            GUICtrlSetData($cInput_Start + 1 + ($i - 1) * 2, $sInterval, "Twice a week")
                                        Case 1
                                            GUICtrlSetData($cInput_Start + 1 + ($i - 1) * 2, $sInterval, "Once a week")
                                    EndSwitch
                            EndSwitch
                        Next
                    EndIf
                EndIf
            Case $cAccept ; Show GUI with currently selected items
                Local $aList[25][7], $iIndex = -1
                For $i = $cInput_Start To $cInput_Start + 50 Step 2
                    $sItem = GUICtrlRead($i)
                    If $sItem Then
                        $iIndex += 1
                        $aList[$iIndex][0] = $sItem
                        Switch GUICtrlRead($i + 1)
                            Case "Every day"
                                $aList[$iIndex][1] = 1
                                $aList[$iIndex][2] = 7
                            Case "6 times a week"
                                $aList[$iIndex][1] = 1
                                $aList[$iIndex][2] = 6
                            Case "5 times a week"
                                $aList[$iIndex][1] = 1
                                $aList[$iIndex][2] = 5
                            Case "4 times a week"
                                $aList[$iIndex][1] = 1
                                $aList[$iIndex][2] = 4
                            Case "3 times a week"
                                $aList[$iIndex][1] = 1
                                $aList[$iIndex][2] = 3
                            Case "Twice a week"
                                $aList[$iIndex][1] = 1
                                $aList[$iIndex][2] = 2
                            Case "Once a week"
                                $aList[$iIndex][1] = 1
                                $aList[$iIndex][2] = 1
                            Case "Every 2 weeks"
                                $aList[$iIndex][1] = 2
                                $aList[$iIndex][2] = 0
                            Case "Every 4 weeks"
                                $aList[$iIndex][1] = 4
                                $aList[$iIndex][2] = 0
                        EndSwitch
                        For $j = 3 To 6
                            $aList[$iIndex + 1][$j] = 0
                        Next
                    EndIf
                Next
                If $iIndex = -1 Then Return SetError(2, 0, "") ; Fail if no items
                ReDim $aList[$iIndex][7]
                $aItemBase = $aList
                ExitLoop
        EndSwitch
    WEnd

    ; Check items per day
    $iItemsPerDay = GUICtrlRead($cPerDay)
    If $iItemsPerDay = 0 Then Return SetError(3, 0, "") ; Fail if none

    GUIDelete($hNewGUI)

    ; Create combo list
    $sItemListBase = ""
    For $i = 0 To UBound($aItemBase) - 1
        $sItemListBase &= "|" & $aItemBase[$i][0]
    Next

    ; Create load array
    Local $aLoad_Data[28 * $iItemsPerDay][2]
    For $i = 0 To (28 * $iItemsPerDay) - 1
        $aLoad_Data[$i][0] = $sItemListBase
        $aLoad_Data[$i][1] = ""
    Next

    Return $aLoad_Data

EndFunc   ;==>_Define_New

Func _Update_Combos()

    ; Disable GUI until function terminates - just prevents selecting another combo before reloading has finished
    GUISetState(@SW_DISABLE, $hMainGui)

    ; First we create a copy of the $aItems array so we can see what is and is not set this time around.
    Local $aItems = $aItemBase
    For $i = 0 To 3 ; Weeks
        For $j = 0 To 34 ; Combos
            $sSel = GUICtrlRead($cCombo_Start + $j + ($i * 35))

            If $sSel Then
                ; Find index of selected item in the array
                $iIndex = _ArraySearch($aItems, $sSel)
                ; Set for correct week
                $aItems[$iIndex][$i + 3] += 1 ; Set week true
            EndIf
        Next
    Next

    ; Copy base combo list - one for each week
    Local $aItemList[5] = ["", $sItemListBase & "|", $sItemListBase & "|", $sItemListBase & "|", $sItemListBase & "|"]

    For $i = 0 To UBound($aItems) - 1
        ; Check required interval
        Switch $aItems[$i][1]
            Case 1 ; Weekly or more
                For $j = 1 To 4
                    ; Get current count for this item in this week
                    $iCurrent_Count = $aItems[$i][$j + 2]
                    ; Compare to max required per week
                    If $iCurrent_Count = $aItems[$i][2] Then
                        ; Remove from the list for this week only
                        $aItemList[$j] = StringReplace($aItemList[$j], "|" & $aItems[$i][0] & "|", "|")
                    EndIf
                Next
            Case 2 ; Once every 2 weeks
                For $k = 0 To 2 Step 2
                    ; If chosen in this section
                    $iCount = 0
                    For $j = 1 To 2
                        $iCount += $aItems[$i][$j + $k + 2]
                    Next
                    If $iCount Then
                        $sLists = "1 & 2"
                        If $k Then $sLists = "3 & 4"
                        ; Remove from both lists for this section
                        For $j = 1 + $k To 2 + $k
                            $aItemList[$j] = StringReplace($aItemList[$j], "|" & $aItems[$i][0] & "|", "|")
                        Next
                    EndIf
                Next
            Case 4 ; Once every 4 weeks
                $iCount = 0
                For $j = 1 To 4
                    $iCount += $aItems[$i][$j + 2]
                Next
                If $iCount Then
                    ; Remove from all lists
                    For $j = 1 To 4
                        $aItemList[$j] = StringReplace($aItemList[$j], "|" & $aItems[$i][0] & "|", "|")
                    Next
                EndIf
        EndSwitch
    Next

    ; Now fill combos - allowing each item to be selected only once per day
    For $i = 0 To 3 ; Weeks
        For $j = 0 To 34 Step $iItemsPerDay ; Combo blocks by day
            ; For each day get data string for this week
            $sDataDay = $aItemList[$i + 1]
            For $k = 0 To $iItemsPerDay - 1 ; Combos in block
                ; Read combos
                $sSel = GUICtrlRead($cCombo_Start + $k + $j + ($i * 35))
                ; Remove currently selected items from day list
                $sDataDay = StringReplace($sDataDay, "|" & $sSel & "|", "|")
            Next
            ; Now add day list to each combo, re-adding current selection if there is one
            For $k = 0 To $iItemsPerDay - 1
                $sSel = GUICtrlRead($cCombo_Start + $k + $j + ($i * 35))
                $sDataCombo = StringTrimRight($sDataDay, 1)
                If $sSel Then
                    $sDataCombo &= "|" & $sSel
                EndIf
                ; Load combo
                GUICtrlSetData($cCombo_Start + $k + $j + ($i * 35), $sDataCombo, $sSel)
            Next
        Next
    Next

    ; Re-enable GUI
    GUISetState(@SW_ENABLE, $hMainGui)

EndFunc   ;==>_Update_Combos

Func _Load_Sim() ; Just for testing
#Tidy_Off
    ;         Item,                 Interval (1, 2, 4 weeks),   Times weekly if weekly,     Count in week 1,2,3,4
    Global $aItemBase[22][7] = [ _
            ['Kitchen',             1,                          3,                          0, 0, 0, 0], _
            ['Master Bed Room',     1,                          3,                          0, 0, 0, 0], _
            ['Front Bed Room',      2,                          0,                          0, 0, 0, 0], _
            ['Back Bed Room',       2,                          0,                          0, 0, 0, 0], _
            ['Bathroom Full',       1,                          2,                          0, 0, 0, 0], _
            ['Bathroom Half',       2,                          2,                          0, 0, 0, 0], _
            ['Living Room',         1,                          1,                          0, 0, 0, 0], _
            ['Dining Bar',          1,                          2,                          0, 0, 0, 0], _
            ['Dining Porch',        2,                          0,                          0, 0, 0, 0], _
            ['Basement',            4,                          0,                          0, 0, 0, 0], _
            ['Garage',              4,                          0,                          0, 0, 0, 0], _
            ['Laundry Room',        2,                          0,                          0, 0, 0, 0], _
            ['Lawn (Cutting)',      2,                          0,                          0, 0, 0, 0], _
            ['Storage',             4,                          0,                          0, 0, 0, 0], _
            ['Porch',               2,                          0,                          0, 0, 0, 0], _
            ['Closed Porch',        2,                          0,                          0, 0, 0, 0], _
            ['Weed Pulling',        2,                          0,                          0, 0, 0, 0], _
            ['Misc1',               4,                          0,                          0, 0, 0, 0], _
            ['Misc2',               4,                          0,                          0, 0, 0, 0], _
            ['Misc3',               4,                          0,                          0, 0, 0, 0], _
            ['Misc4',               4,                          0,                          0, 0, 0, 0], _
            ['Misc5',               1,                          2,                          0, 0, 0, 0]]
    #Tidy_On

    $iItemsPerDay = 5
    ; Create combo list
    For $i = 0 To UBound($aItemBase) - 1
        $sItemListBase &= "|" & $aItemBase[$i][0]
    Next
    Local $aLoad_Data[28 * 5][2]
    For $i = 0 To (28 * 5) - 1
        $aLoad_Data[$i][0] = $sItemListBase
        $aLoad_Data[$i][1] = ""
    Next

    Return $aLoad_Data

EndFunc   ;==>_Load_Sim

Over to you now.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

That is freaking cool as $hit...I cannot wait to take a look at this. I am almost off work, and I have my son this weekend, so will not get to it until next week. BUT I am really looking forward to looking at your code, so I may just stay up and play with it.

 

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

  • 2 weeks later...

Okay...sorry it took a while, but I had looked at it last weekend, but did not quite finish. I think it works now. I only made a few changes...the create new chore list, had to have a few more indexes. I added the ability to save after accepting changes to the list. And added the save question before exit.

I have some more ideas...about how to establish a set of goals for each list item. For instance, I had an idea for a start/stop timer for the task, and a new best time record, say for cleaning the kitchen - when a new best time is made, a prize or reward. So I guess, now I will have a list of rewards (not sure if the reward should be random, or choose, or per chore). Another idea might be for the task to be completed, if completed for the amount of times (Times per month, and times per week) then reward is given.

Anything you can think of that might make it better?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <AutoItConstants.au3>
#include <StaticConstants.au3>
#include <GuiComboBox.au3>
#include <Array.au3>

Global $aLoad_Data, $aItemBase, $hMainGui, $cCombo_Start, $iItemsPerDay, $sItemListBase


If $CmdLine[0] Then
    $sFile = $CmdLine[1]
    $aLoad_Data = _Load_State(@ScriptDir & "\" & $sFile)
Else
    Switch MsgBox($MB_SYSTEMMODAL + $MB_YESNOCANCEL, "Load", "Load an existing file?")
        Case $IDYES
            $aLoad_Data = _Load_State()
            If @error Then Exit
        Case $IDNO
            $aLoad_Data = _Define_New()
            If @error Then Exit
        Case Else
            ; Exit
            $aLoad_Data = _Load_Sim() ; Just to use the currently defined data for testing
    EndSwitch
EndIf

_Create_GUI()

Func _Create_GUI()

    SplashTextOn("Inititalising", "Please be patient", 300, 100)

    Local $iWeekSpacing = (20 * $iItemsPerDay) + 25, $iWeekOffset = $iWeekSpacing - 40
    Local $iDaySpacing = 155, $iDayOffset = 45, $iComboOffset = 21

    $hMainGui = GUICreate('Item Schedule', 1200, (4 * $iWeekSpacing) + 60)

    $mFile = GUICtrlCreateMenu("&File")
    $mFileNew = GUICtrlCreateMenuItem("&New", $mFile)
    $mFileLoad = GUICtrlCreateMenuItem("&Load", $mFile)
    $mFileSave = GUICtrlCreateMenuItem("&Save", $mFile)
    GUICtrlSetState(-1, $GUI_DEFBUTTON)

    GUICtrlCreateMenuItem("", $mFile)
    $mFileExit = GUICtrlCreateMenuItem("E&xit", $mFile)

    ; Create labels
    For $i = 1 To 4
        GUICtrlCreateLabel('Week ' & $i, 10, ($i * $iWeekSpacing) - $iWeekOffset)
    Next
    Local $aDay[8] = ["", 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
    For $i = 1 To 7
        GUICtrlCreateLabel($aDay[$i], $iDaySpacing * ($i) - $iDayOffset, 10, 125, 20, $SS_CENTER)
    Next

    ; Create combos
    $cCombo_Start = GUICtrlCreateDummy() + 1
    $iIndex = 0
    For $i = 1 To 4 ; Weeks
        $iY_Base = ($i * $iWeekSpacing) - $iWeekOffset
        For $j = 1 To 7 ; Days
            $iX = ($iDaySpacing * $j) - $iDayOffset
            For $k = 0 To $iItemsPerDay - 1 ; Items
                $iY = $iY_Base + ($iComboOffset * $k)
                GUICtrlCreateCombo("", $iX, $iY, 125, 20, $CBS_DROPDOWNLIST)
                GUICtrlSetData(-1, $aLoad_Data[$iIndex][0], $aLoad_Data[$iIndex][1])
                $iIndex += 1
            Next
        Next
    Next
    $cCombo_End = GUICtrlCreateDummy() - 1

    SplashOff()

    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $mFileExit
                ; added - so that they would have a chance to save before exit
                If MsgBox($MB_YESNO, 'Do you want to save changes?', 'Do you want to save changes, before you exit') <> 6 Then
                    Exit
                Else
                    _Save_State()
                    If @error Then
                        MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "Error", "Save failed")
                    Else
                        Exit
                    EndIf
                EndIf
            Case $cCombo_Start To $cCombo_End ; Combo actioned
                _Update_Combos()
            Case $mFileNew
                $aLoad_Data = _Define_New()
                If Not @error Then
                    GUIDelete($hMainGui)
                    _Create_GUI()
                EndIf
            Case $mFileLoad
                $aLoad_Data = _Load_State()
                GUIDelete($hMainGui)
                _Create_GUI()
            Case $mFileSave
                _Save_State()
                If @error Then
                    MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "Error", "Save failed")
                EndIf
        EndSwitch

    WEnd

EndFunc   ;==>_Create_GUI

Func _Load_State($sFile = "")

    If Not $sFile Then
        $sFile = FileOpenDialog("Open", @ScriptDir, "All (*.*)")
    EndIf

    If $sFile Then
        ; Read data from saved file
        $iItemsPerDay = IniRead($sFile, "Base", "ItemsPerDay", "Error")
        If @error Then Return SetError(1, 0, "")
        $sItemListBase = IniRead($sFile, "Base", "ItemList", "Error")
        If @error Then Return SetError(2, 0, "")
        $sBaseArray = IniRead($sFile, "Base", "BaseArray", "Error")
        If @error Then Return SetError(3, 0, "")

        ; Create required base array
        Local $aLines = StringSplit($sBaseArray, "|")
        Global $aItemBase[$aLines[0]][7]
        For $i = 1 To $aLines[0]
            $aSplit = StringSplit($aLines[$i], ",")
            $aItemBase[$i - 1][0] = $aSplit[1]
            $aItemBase[$i - 1][1] = $aSplit[2]
            $aItemBase[$i - 1][2] = $aSplit[3]
            For $j = 3 To 6
                $aItemBase[$i - 1][$j] = 0
            Next
        Next

        ; Create array holding individual combo data
        $iTotal = 4 * 7 * $iItemsPerDay
        Local $aList[$iTotal][2]
        For $i = 0 To $iTotal - 1
            $sVal = IniRead($sFile, "Combos", $i, "Error")
            If @error Then
                Return SetError(4, 0, "")
            Else
                $aSplit = StringSplit($sVal, ",")
                $aList[$i][0] = $aSplit[1]
                $aList[$i][1] = $aSplit[2]
            EndIf
        Next
        Return $aList
    Else
        Return SetError(1, 0, "")
    EndIf

EndFunc   ;==>_Load_State

Func _Save_State($sFileName = '')
    If $sFileName = '' Then
        $sFile = FileSaveDialog("Save As", @ScriptDir, "All (*.*)")
        If @error Then Return SetError(1, 0, "")
    Else
        $sFile = $sFileName
    EndIf
    ; Write data
    IniWrite($sFile, "Base", "ItemsPerDay", $iItemsPerDay)
    IniWrite($sFile, "Base", "ItemList", $sItemListBase)
    For $j = 0 To (4 * 7 * $iItemsPerDay) - 1
        IniWrite($sFile, "Combos", $j, _GUICtrlComboBox_GetList($cCombo_Start + $j) & "," & GUICtrlRead($cCombo_Start + $j))
    Next
    $sBaseArray = ""
    For $i = 0 To UBound($aItemBase, $UBOUND_ROWS) - 1
        For $j = 0 To 2
            $sBaseArray &= $aItemBase[$i][$j] & ","
        Next
        $sBaseArray = StringTrimRight($sBaseArray, 1) & "|"
    Next
    IniWrite($sFile, "Base", "BaseArray", StringTrimRight($sBaseArray, 1))

EndFunc   ;==>_Save_State

Func _Define_New()

    ; Create default interval list
    Local $sInterval = "|Every day|6 times a week|5 times a week|4 times a week|3 times a week|Twice a week|Once a week|Every 2 weeks|Every 4 weeks"
    Local $aList = "", $sFile = '', $sDefault = "Every day"

    ; Create GUI
    $hNewGUI = GUICreate("Create New List", 430, 680, Default, Default, Default, Default, $hMainGui)

    $cInput_Start = GUICtrlCreateDummy() + 1
    For $i = 0 To 24
        GUICtrlCreateInput("", 10, 10 + (25 * $i), 200, 20)
        GUICtrlCreateCombo("", 220, 10 + (25 * $i), 200, 20, $CBS_DROPDOWNLIST)
        GUICtrlSetData(-1, $sInterval, $sDefault)
    Next
    $cPerDay = GUICtrlCreateCombo("", 10, 645, 100, 20, $CBS_DROPDOWNLIST)
    GUICtrlSetData($cPerDay, "1|2|3|4|5")
    GUICtrlCreateLabel("Items per day", 120, 650, 100, 20)
    $cAmend = GUICtrlCreateButton("Amend", 220, 640, 60, 30)
    $cAccept = GUICtrlCreateButton("Accept", 290, 640, 60, 30)
    $cCancel = GUICtrlCreateButton("Cancel", 360, 640, 60, 30)

    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $cCancel
                GUIDelete($hNewGUI)
                Return SetError(1, 0, "")
            Case $cAmend ; Load existing file to amend data
                $sFile = FileOpenDialog("Open", @ScriptDir, "All (*.*)")
                If $sFile Then
                    ; Check load was correct
                    $bError = False
                    $iLocalItemsPerDay = IniRead($sFile, "Base", "ItemsPerDay", "Error")
                    If @error Then $bError = True
                    $sLocalBaseArray = IniRead($sFile, "Base", "BaseArray", "Error")
                    If @error Then $bError = True
                    If Not $bError Then
                        ; Fill GUI with loaded data
                        GUICtrlSetData($cPerDay, '')
                        GUICtrlSetData($cPerDay, "1|2|3|4|5", $iLocalItemsPerDay)
                        Local $aLines = StringSplit($sLocalBaseArray, "|")
                        For $i = 1 To $aLines[0]
                            $aSplit = StringSplit($aLines[$i], ",")
                            GUICtrlSetData($cInput_Start + ($i - 1) * 2, $aSplit[1])
                            Switch $aSplit[2]
                                Case 4
                                    GUICtrlSetData($cInput_Start + 1 + ($i - 1) * 2, $sInterval, "Every 4 weeks")
                                Case 2
                                    GUICtrlSetData($cInput_Start + 1 + ($i - 1) * 2, $sInterval, "Every 2 weeks")
                                Case 1
                                    Switch $aSplit[3]
                                        Case 7
                                            GUICtrlSetData($cInput_Start + 1 + ($i - 1) * 2, $sInterval, "Every day")
                                        Case 6
                                            GUICtrlSetData($cInput_Start + 1 + ($i - 1) * 2, $sInterval, "6 times a week")
                                        Case 5
                                            GUICtrlSetData($cInput_Start + 1 + ($i - 1) * 2, $sInterval, "5 times a week")
                                        Case 4
                                            GUICtrlSetData($cInput_Start + 1 + ($i - 1) * 2, $sInterval, "4 times a week")
                                        Case 3
                                            GUICtrlSetData($cInput_Start + 1 + ($i - 1) * 2, $sInterval, "3 times a week")
                                        Case 2
                                            GUICtrlSetData($cInput_Start + 1 + ($i - 1) * 2, $sInterval, "Twice a week")
                                        Case 1
                                            GUICtrlSetData($cInput_Start + 1 + ($i - 1) * 2, $sInterval, "Once a week")
                                    EndSwitch
                            EndSwitch
                        Next

                    EndIf
                EndIf
            Case $cAccept ; Show GUI with currently selected items
                If $sFile = '' Then
                    MsgBox('', Default, 'You will need to create a default file, or creat a new one???')
                    ContinueLoop
                EndIf
                Local $aList[27][7], $iIndex = -1 ; changed - 24 index was too small
                For $i = $cInput_Start To $cInput_Start + 50 Step 2
                    $sItem = GUICtrlRead($i)
                    If $sItem Then
                        $iIndex += 1
                        $aList[$iIndex][0] = $sItem
                        Switch GUICtrlRead($i + 1)
                            Case "Every day"
                                $aList[$iIndex][1] = 1
                                $aList[$iIndex][2] = 7
                            Case "6 times a week"
                                $aList[$iIndex][1] = 1
                                $aList[$iIndex][2] = 6
                            Case "5 times a week"
                                $aList[$iIndex][1] = 1
                                $aList[$iIndex][2] = 5
                            Case "4 times a week"
                                $aList[$iIndex][1] = 1
                                $aList[$iIndex][2] = 4
                            Case "3 times a week"
                                $aList[$iIndex][1] = 1
                                $aList[$iIndex][2] = 3
                            Case "Twice a week"
                                $aList[$iIndex][1] = 1
                                $aList[$iIndex][2] = 2
                            Case "Once a week"
                                $aList[$iIndex][1] = 1
                                $aList[$iIndex][2] = 1
                            Case "Every 2 weeks"
                                $aList[$iIndex][1] = 2
                                $aList[$iIndex][2] = 0
                            Case "Every 4 weeks"
                                $aList[$iIndex][1] = 4
                                $aList[$iIndex][2] = 0
                        EndSwitch
                        For $j = 3 To 6
                            $aList[$iIndex + 1][$j] = 0
                        Next
                    EndIf

                Next
                If $iIndex = -1 Then Return SetError(2, 0, "") ; Fail if no items
                ReDim $aList[$iIndex][7]
                $aItemBase = $aList
                _Save_State($sFile) ; added this line, so that after the data has been updated, it saves to appended file
                If @error Then
                    MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "Error", "Save failed")
                EndIf
                ExitLoop
        EndSwitch
    WEnd

    ; Check items per day
    $iItemsPerDay = GUICtrlRead($cPerDay)
    If $iItemsPerDay = 0 Then Return SetError(3, 0, "") ; Fail if none

    GUIDelete($hNewGUI)

    ; Create combo list
    $sItemListBase = ""
    For $i = 0 To UBound($aItemBase) - 1
        $sItemListBase &= "|" & $aItemBase[$i][0]
    Next

    ; Create load array
    Local $aLoad_Data[28 * $iItemsPerDay][2]
    For $i = 0 To (28 * $iItemsPerDay) - 1
        $aLoad_Data[$i][0] = $sItemListBase
        $aLoad_Data[$i][1] = ""
    Next

    Return $aLoad_Data

EndFunc   ;==>_Define_New

Func _Update_Combos()

    ; Disable GUI until function terminates - just prevents selecting another combo before reloading has finished
    GUISetState(@SW_DISABLE, $hMainGui)

    ; First we create a copy of the $aItems array so we can see what is and is not set this time around.
    Local $aItems = $aItemBase
    For $i = 0 To 3 ; Weeks
        For $j = 0 To 34 ; Combos
            $sSel = GUICtrlRead($cCombo_Start + $j + ($i * 35))

            If $sSel Then
                ; Find index of selected item in the array
                $iIndex = _ArraySearch($aItems, $sSel)
                ; Set for correct week
                $aItems[$iIndex][$i + 3] += 1 ; Set week true
            EndIf
        Next
    Next

    ; Copy base combo list - one for each week
    Local $aItemList[5] = ["", $sItemListBase & "|", $sItemListBase & "|", $sItemListBase & "|", $sItemListBase & "|"]

    For $i = 0 To UBound($aItems) - 1
        ; Check required interval
        Switch $aItems[$i][1]
            Case 1 ; Weekly or more
                For $j = 1 To 4
                    ; Get current count for this item in this week
                    $iCurrent_Count = $aItems[$i][$j + 2]
                    ; Compare to max required per week
                    If $iCurrent_Count = $aItems[$i][2] Then
                        ; Remove from the list for this week only
                        $aItemList[$j] = StringReplace($aItemList[$j], "|" & $aItems[$i][0] & "|", "|")
                    EndIf
                Next
            Case 2 ; Once every 2 weeks
                For $k = 0 To 2 Step 2
                    ; If chosen in this section
                    $iCount = 0
                    For $j = 1 To 2
                        $iCount += $aItems[$i][$j + $k + 2]
                    Next
                    If $iCount Then
                        $sLists = "1 & 2"
                        If $k Then $sLists = "3 & 4"
                        ; Remove from both lists for this section
                        For $j = 1 + $k To 2 + $k
                            $aItemList[$j] = StringReplace($aItemList[$j], "|" & $aItems[$i][0] & "|", "|")
                        Next
                    EndIf
                Next
            Case 4 ; Once every 4 weeks
                $iCount = 0
                For $j = 1 To 4
                    $iCount += $aItems[$i][$j + 2]
                Next
                If $iCount Then
                    ; Remove from all lists
                    For $j = 1 To 4
                        $aItemList[$j] = StringReplace($aItemList[$j], "|" & $aItems[$i][0] & "|", "|")
                    Next
                EndIf
        EndSwitch
    Next

    ; Now fill combos - allowing each item to be selected only once per day
    For $i = 0 To 3 ; Weeks
        For $j = 0 To 34 Step $iItemsPerDay ; Combo blocks by day
            ; For each day get data string for this week
            $sDataDay = $aItemList[$i + 1]
            For $k = 0 To $iItemsPerDay - 1 ; Combos in block
                ; Read combos
                $sSel = GUICtrlRead($cCombo_Start + $k + $j + ($i * 35))
                ; Remove currently selected items from day list
                $sDataDay = StringReplace($sDataDay, "|" & $sSel & "|", "|")
            Next
            ; Now add day list to each combo, re-adding current selection if there is one
            For $k = 0 To $iItemsPerDay - 1
                $sSel = GUICtrlRead($cCombo_Start + $k + $j + ($i * 35))
                $sDataCombo = StringTrimRight($sDataDay, 1)
                If $sSel Then
                    $sDataCombo &= "|" & $sSel
                EndIf
                ; Load combo
                GUICtrlSetData($cCombo_Start + $k + $j + ($i * 35), $sDataCombo, $sSel)
            Next
        Next
    Next

    ; Re-enable GUI
    GUISetState(@SW_ENABLE, $hMainGui)

EndFunc   ;==>_Update_Combos

Func _Load_Sim() ; Just for testing
#Tidy_Off
    ;         Item,                 Interval (1, 2, 4 weeks),   Times weekly if weekly,     Count in week 1,2,3,4
    Global $aItemBase[22][7] = [ _
            ['Kitchen',             1,                          3,                          0, 0, 0, 0], _
            ['Master Bed Room',     1,                          3,                          0, 0, 0, 0], _
            ['Front Bed Room',      2,                          0,                          0, 0, 0, 0], _
            ['Back Bed Room',       2,                          0,                          0, 0, 0, 0], _
            ['Bathroom Full',       1,                          2,                          0, 0, 0, 0], _
            ['Bathroom Half',       2,                          2,                          0, 0, 0, 0], _
            ['Living Room',         1,                          1,                          0, 0, 0, 0], _
            ['Dining Bar',          1,                          2,                          0, 0, 0, 0], _
            ['Dining Porch',        2,                          0,                          0, 0, 0, 0], _
            ['Basement',            4,                          0,                          0, 0, 0, 0], _
            ['Garage',              4,                          0,                          0, 0, 0, 0], _
            ['Laundry Room',        2,                          0,                          0, 0, 0, 0], _
            ['Lawn (Cutting)',      2,                          0,                          0, 0, 0, 0], _
            ['Storage',             4,                          0,                          0, 0, 0, 0], _
            ['Porch',               2,                          0,                          0, 0, 0, 0], _
            ['Closed Porch',        2,                          0,                          0, 0, 0, 0], _
            ['Weed Pulling',        2,                          0,                          0, 0, 0, 0], _
            ['Misc1',               4,                          0,                          0, 0, 0, 0], _
            ['Misc2',               4,                          0,                          0, 0, 0, 0], _
            ['Misc3',               4,                          0,                          0, 0, 0, 0], _
            ['Misc4',               4,                          0,                          0, 0, 0, 0], _
            ['Misc5',               1,                          2,                          0, 0, 0, 0]]
     #Tidy_On

    $iItemsPerDay = 5
    ; Create combo list
    For $i = 0 To UBound($aItemBase) - 1
        $sItemListBase &= "|" & $aItemBase[$i][0]
    Next
    Local $aLoad_Data[28 * 5][2]
    For $i = 0 To (28 * 5) - 1
        $aLoad_Data[$i][0] = $sItemListBase
        $aLoad_Data[$i][1] = ""
    Next

    Return $aLoad_Data

EndFunc   ;==>_Load_Sim

 

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

  • Moderators

nitekram,

I think it works now

Nice to hear.

M23 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...