Jump to content
nooneclose

[SOLVED] How do I find every other Saturday in any month?

Recommended Posts

I forgot an important and needed aspect of my code. I need to be able to check for people who work every other week. Is it possible to write the dates that they work (every other week) between two date ranges? 

Example:  Bob Smith has a Start date of 8-26-2018 (that is the date he is hired) And He stops working on 12-12-18 (that's the day he goes on vacation or whatever) However his work shift is every other Saturday from 7:30 AM to 6:00 Pm.  I need to calculate every other Saturday between 8-26-18 and 12-12-18 (is this clear?)

 

here is the code I have so far. I am just missing this last part:

; Step 7
Func SendData()

    ;*******************************************************************************
    ; Sends all collected data to the Excel file in correct order for Upload
    ;*******************************************************************************
    MsgBox($MB_ICONINFORMATION, "Scheduler_Bot", "Sending Data", 2)

    ; Loop Counters
    $LoopCount   = 0
    $Array_Index = 0
    $DayIndex    = 0
    $dataIndex   = 0

    ; Counter for the day of the week
    Local $dCount = 2

    ; Counter for the numbers of Ys
    Local $yesCount = 0

    ; Excel Write Counter (VERY IMPORTANT!)
    Local $EWriteCount = 2

    ; Declare the global shift arrays (Sunday - Saturday)
    Global $ShiftDaySU[100][600]
    Global $ShiftDayM[100][600]
    Global $ShiftDayT[100][600]
    Global $ShiftDayW[100][600]
    Global $ShiftDayR[100][600]
    Global $ShiftDayF[100][600]
    Global $ShiftDayS[100][600]
    Global $sDates[400]

    While $Formatted_Names[$dataIndex] <> $Formatted_Names[$IndexRows] ; $LoopCount < $IndexRows

        $ACounter = 0 ; Array counter

        ; Gets the Start date from the array
        $Temp = $StartDate[$Array_Index]
        $TempStart = StringLeft($Temp, 8)
        $StartTempYear  = StringLeft($TempStart, 4)
        $StartTempMonth = StringMid($TempStart, 5, 2)
        $StartTempDay   = StringRight($TempStart, 2)

        ; Gets the End date from the array
        $Temp = $EndDate[$Array_Index]
        $TempEnd = StringLeft($Temp, 8)
        $EndTempYear  = StringLeft($TempEnd, 4)
        $EndTempMonth = StringMid($TempEnd, 5, 2)
        $EndTempDay   = StringRight($TempEnd, 2)

        ; The starting date (in value form)
        $sdate = _DateToDayValue($StartTempYear, $StartTempMonth, $StartTempDay)    ;_DateToDayValue(2019,1,9)
        ;ConsoleWrite(@CRLF & "$start date  " & $sdate & @CRLF & @CRLF)

        ; The ending date (in value form)
        $edate = _DateToDayValue($EndTempYear, $EndTempMonth, $EndTempDay)          ;_DateToDayValue(2019,4,9)
        ;ConsoleWrite(@CRLF & "$end date  " & $edate & @CRLF & @CRLF)

        ; Variables for readability
        Local $iYear, $iMonth, $iDay

        ;Stores what day of the week that shift lands on
        Local $tSU = _Excel_RangeRead($OpenWorkbook, Default, "I" & $dCount)
            If $tSU = "Y" Then
                $yesCount = 1
            EndIf
        Local $tM  = _Excel_RangeRead($OpenWorkbook, Default, "J" & $dCount)
            If $tM = "Y" Then
                $yesCount += 1
            EndIf
        Local $tT  = _Excel_RangeRead($OpenWorkbook, Default, "K" & $dCount)
            If $tT = "Y" Then
                $yesCount += 1
            EndIf
        Local $tW  = _Excel_RangeRead($OpenWorkbook, Default, "L" & $dCount)
            If $tW = "Y" Then
                $yesCount += 1
            EndIf
        Local $tR  = _Excel_RangeRead($OpenWorkbook, Default, "M" & $dCount)
            If $tR = "Y" Then
                $yesCount += 1
            EndIf
        Local $tF  = _Excel_RangeRead($OpenWorkbook, Default, "N" & $dCount)
            If $tF = "Y" Then
                $yesCount += 1
            EndIf
        Local $tS  = _Excel_RangeRead($OpenWorkbook, Default, "O" & $dCount)
            If $tS = "Y" Then
                $yesCount += 1
            EndIf

        ConsoleWrite(@CRLF & @CRLF)
        ConsoleWrite($tSU & @CRLF)
        ConsoleWrite($tM & @CRLF)
        ConsoleWrite($tT & @CRLF)
        ConsoleWrite($tW & @CRLF)
        ConsoleWrite($tR & @CRLF)
        ConsoleWrite($tF & @CRLF)
        ConsoleWrite($tS & @CRLF)
        ConsoleWrite(@CRLF & @CRLF)

        ; Check to see if they work every other week
        Local $rotationWeek  = _Excel_RangeRead($OpenWorkbook, Default, "U" & $dCount)
            If $rotationWeek = "0" Then
                ; Do nothing
            Else
                If $rotationWeek = 1
                    ; Do something
                Else ; $rotationWeek = 2
                    ; Do something
                EndIf
            EndIf

        Local $repeatWeek  = _Excel_RangeRead($OpenWorkbook, Default, "V" & $dCount)
            If $rotationWeek = "0" Then
                ; Do nothing
            Else
                If $rotationWeek = 1
                    ; Do something
                Else ; $rotationWeek = 2
                    ; Do something
                EndIf
            EndIf

        While $yesCount > 0

            If $tSU = "Y" Then
                For $Index = $sdate To $edate
                    _DayValueToDate($Index, $iYear, $iMonth, $iDay)
                    ; Finds the day based on its numerical value (1 = Sunday)
                    If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 1 Then
                        $Temp = $iYear & "-" & $iMonth & "-" & $iDay & "T" & "00" & ":" & "00" & ":" & "00" & ":" & "000"
                        $ShiftDaySU[$ACounter][$DayIndex] = $Temp
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $ShiftDaySU[$ACounter][$DayIndex], "AI" & $EWriteCount)

                        ; Send Name
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Formatted_Names[$dataIndex], "AA" & $EWriteCount)
                        ; Send Start Time
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $StartTimes[$dataIndex], "AB" & $EWriteCount)
                        ; Send End Time
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $EndTimes[$dataIndex], "AC" & $EWriteCount)
                        ; Send Work Hours
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $HoursWorked[$dataIndex], "AD" & $EWriteCount)
                        ; Send Work Group
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkGroup[$dataIndex], "AE" & $EWriteCount)
                        ; Send Department
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkDepartment, "AF" & $EWriteCount)
                        ; Send Supervisor
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Supervisors[$dataIndex], "AG" & $EWriteCount)
                        ; Send Notes
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkNotes[$dataIndex], "AH" & $EWriteCount)

                        ; Send Shift Number
                        $tempStime = StringReplace($StartTimes[$dataIndex], ":", "")
                        $tempEtime = StringReplace($EndTimes[$dataIndex], ":", "")
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, "SU " & $tempStime & "-" & $tempEtime, "AJ" & $EWriteCount)

                        $ACounter    += 1
                        $EWriteCount += 1

                        ConsoleWrite(@CRLF & "Sunday  " & $Temp & @CRLF)

                    EndIf
                Next

                $yesCount -= 1
                $tSU = "N"

            ElseIf $tM = "Y" Then
                For $Index = $sdate To $edate
                    _DayValueToDate($Index, $iYear, $iMonth, $iDay)
                    ; Finds the day based on its numerical value (1 = Sunday)
                    If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 2 Then
                        $Temp = $iYear & "-" & $iMonth & "-" & $iDay & "T" & "00" & ":" & "00" & ":" & "00" & ":" & "000"
                        $ShiftDayM[$ACounter][$DayIndex] = $Temp
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $ShiftDayM[$ACounter][$DayIndex], "AI" & $EWriteCount)

                        ; Send Name
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Formatted_Names[$dataIndex], "AA" & $EWriteCount)
                        ; Send Start Time
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $StartTimes[$dataIndex], "AB" & $EWriteCount)
                        ; Send End Time
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $EndTimes[$dataIndex], "AC" & $EWriteCount)
                        ; Send Work Hours
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $HoursWorked[$dataIndex], "AD" & $EWriteCount)
                        ; Send Work Group
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkGroup[$dataIndex], "AE" & $EWriteCount)
                        ; Send Department
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkDepartment, "AF" & $EWriteCount)
                        ; Send Supervisor
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Supervisors[$dataIndex], "AG" & $EWriteCount)
                        ; Send Notes
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkNotes[$dataIndex], "AH" & $EWriteCount)

                        ; Send Shift Number
                        $tempStime = StringReplace($StartTimes[$dataIndex], ":", "")
                        $tempEtime = StringReplace($EndTimes[$dataIndex], ":", "")
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, "M " & $tempStime & "-" & $tempEtime, "AJ" & $EWriteCount)

                        $ACounter    += 1
                        $EWriteCount += 1

                        ConsoleWrite(@CRLF & "Monday  " & $Temp & @CRLF)

                    EndIf
                Next

                $yesCount -= 1
                $tM = "N"

            ElseIf $tT = "Y" Then
                For $Index = $sdate To $edate
                    _DayValueToDate($Index, $iYear, $iMonth, $iDay)
                    ; Finds the day based on its numerical value (1 = Sunday)
                    If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 3 Then
                        $Temp = $iYear & "-" & $iMonth & "-" & $iDay & "T" & "00" & ":" & "00" & ":" & "00" & ":" & "000"
                        $ShiftDayT[$ACounter][$DayIndex] = $Temp
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $ShiftDayT[$ACounter][$DayIndex], "AI" & $EWriteCount)

                        ; Send Name
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Formatted_Names[$dataIndex], "AA" & $EWriteCount)
                        ; Send Start Time
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $StartTimes[$dataIndex], "AB" & $EWriteCount)
                        ; Send End Time
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $EndTimes[$dataIndex], "AC" & $EWriteCount)
                        ; Send Work Hours
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $HoursWorked[$dataIndex], "AD" & $EWriteCount)
                        ; Send Work Group
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkGroup[$dataIndex], "AE" & $EWriteCount)
                        ; Send Department
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkDepartment, "AF" & $EWriteCount)
                        ; Send Supervisor
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Supervisors[$dataIndex], "AG" & $EWriteCount)
                        ; Send Notes
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkNotes[$dataIndex], "AH" & $EWriteCount)

                        ; Send Shift Number
                        $tempStime = StringReplace($StartTimes[$dataIndex], ":", "")
                        $tempEtime = StringReplace($EndTimes[$dataIndex], ":", "")
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, "T " & $tempStime & "-" & $tempEtime, "AJ" & $EWriteCount)

                        $ACounter    += 1
                        $EWriteCount += 1

                        ConsoleWrite(@CRLF & "Tuesday  " & $Temp & @CRLF)

                    EndIf
                Next

                $yesCount -= 1
                $tT = "N"

            ElseIf $tW = "Y" Then
                For $Index = $sdate To $edate
                    _DayValueToDate($Index, $iYear, $iMonth, $iDay)
                    ; Finds the day based on its numerical value (1 = Sunday)
                    If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 4 Then
                        $Temp = $iYear & "-" & $iMonth & "-" & $iDay & "T" & "00" & ":" & "00" & ":" & "00" & ":" & "000"
                        $ShiftDayW[$ACounter][$DayIndex] = $Temp
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $ShiftDayW[$ACounter][$DayIndex], "AI" & $EWriteCount)

                        ; Send Name
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Formatted_Names[$dataIndex], "AA" & $EWriteCount)
                        ; Send Start Time
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $StartTimes[$dataIndex], "AB" & $EWriteCount)
                        ; Send End Time
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $EndTimes[$dataIndex], "AC" & $EWriteCount)
                        ; Send Work Hours
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $HoursWorked[$dataIndex], "AD" & $EWriteCount)
                        ; Send Work Group
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkGroup[$dataIndex], "AE" & $EWriteCount)
                        ; Send Department
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkDepartment, "AF" & $EWriteCount)
                        ; Send Supervisor
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Supervisors[$dataIndex], "AG" & $EWriteCount)
                        ; Send Notes
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkNotes[$dataIndex], "AH" & $EWriteCount)

                        ; Send Shift Number
                        $tempStime = StringReplace($StartTimes[$dataIndex], ":", "")
                        $tempEtime = StringReplace($EndTimes[$dataIndex], ":", "")
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, "W " & $tempStime & "-" & $tempEtime, "AJ" & $EWriteCount)

                        $ACounter    += 1
                        $EWriteCount += 1

                        ConsoleWrite(@CRLF & "Wednesday  " & $Temp & @CRLF)

                    EndIf
                Next

                $yesCount -= 1
                $tW = "N"

            ElseIf $tR = "Y" Then
                For $Index = $sdate To $edate
                    _DayValueToDate($Index, $iYear, $iMonth, $iDay)
                    ; Finds the day based on its numerical value (1 = Sunday)
                    If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 5 Then
                        $Temp = $iYear & "-" & $iMonth & "-" & $iDay & "T" & "00" & ":" & "00" & ":" & "00" & ":" & "000"
                        $ShiftDayR[$ACounter][$DayIndex] = $Temp
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $ShiftDayR[$ACounter][$DayIndex], "AI" & $EWriteCount)

                        ; Send Name
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Formatted_Names[$dataIndex], "AA" & $EWriteCount)
                        ; Send Start Time
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $StartTimes[$dataIndex], "AB" & $EWriteCount)
                        ; Send End Time
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $EndTimes[$dataIndex], "AC" & $EWriteCount)
                        ; Send Work Hours
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $HoursWorked[$dataIndex], "AD" & $EWriteCount)
                        ; Send Work Group
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkGroup[$dataIndex], "AE" & $EWriteCount)
                        ; Send Department
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkDepartment, "AF" & $EWriteCount)
                        ; Send Supervisor
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Supervisors[$dataIndex], "AG" & $EWriteCount)
                        ; Send Notes
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkNotes[$dataIndex], "AH" & $EWriteCount)

                        ; Send Shift Number
                        $tempStime = StringReplace($StartTimes[$dataIndex], ":", "")
                        $tempEtime = StringReplace($EndTimes[$dataIndex], ":", "")
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, "R " & $tempStime & "-" & $tempEtime, "AJ" & $EWriteCount)

                        $ACounter    += 1
                        $EWriteCount += 1

                        ConsoleWrite(@CRLF & "Thursday  " & $Temp & @CRLF)

                    EndIf
                Next

                $yesCount -= 1
                $tR = "N"

            ElseIf $tF = "Y" Then
                For $Index = $sdate To $edate
                    _DayValueToDate($Index, $iYear, $iMonth, $iDay)
                    ; Finds the day based on its numerical value (1 = Sunday)
                    If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 6 Then
                        $Temp = $iYear & "-" & $iMonth & "-" & $iDay & "T" & "00" & ":" & "00" & ":" & "00" & ":" & "000"
                        $ShiftDayF[$ACounter][$DayIndex] = $Temp
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $ShiftDayF[$ACounter][$DayIndex], "AI" & $EWriteCount)

                        ; Send Name
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Formatted_Names[$dataIndex], "AA" & $EWriteCount)
                        ; Send Start Time
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $StartTimes[$dataIndex], "AB" & $EWriteCount)
                        ; Send End Time
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $EndTimes[$dataIndex], "AC" & $EWriteCount)
                        ; Send Work Hours
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $HoursWorked[$dataIndex], "AD" & $EWriteCount)
                        ; Send Work Group
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkGroup[$dataIndex], "AE" & $EWriteCount)
                        ; Send Department
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkDepartment, "AF" & $EWriteCount)
                        ; Send Supervisor
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Supervisors[$dataIndex], "AG" & $EWriteCount)
                        ; Send Notes
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkNotes[$dataIndex], "AH" & $EWriteCount)

                        ; Send Shift Number
                        $tempStime = StringReplace($StartTimes[$dataIndex], ":", "")
                        $tempEtime = StringReplace($EndTimes[$dataIndex], ":", "")
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, "F " & $tempStime & "-" & $tempEtime, "AJ" & $EWriteCount)

                        $ACounter    += 1
                        $EWriteCount += 1

                        ConsoleWrite(@CRLF & "Friday  " & $Temp & @CRLF)

                    EndIf
                Next

                $yesCount -= 1
                $tF = "N"

            ElseIf $tS = "Y" Then
                For $Index = $sdate To $edate
                    _DayValueToDate($Index, $iYear, $iMonth, $iDay)
                    ; Finds the day based on its numerical value (1 = Sunday)
                    If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 7 Then
                        $Temp = $iYear & "-" & $iMonth & "-" & $iDay & "T" & "00" & ":" & "00" & ":" & "00" & ":" & "000"
                        $ShiftDayS[$ACounter][$DayIndex] = $Temp
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $ShiftDayS[$ACounter][$DayIndex], "AI" & $EWriteCount)

                        ; Send Name
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Formatted_Names[$dataIndex], "AA" & $EWriteCount)
                        ; Send Start Time
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $StartTimes[$dataIndex], "AB" & $EWriteCount)
                        ; Send End Time
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $EndTimes[$dataIndex], "AC" & $EWriteCount)
                        ; Send Work Hours
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $HoursWorked[$dataIndex], "AD" & $EWriteCount)
                        ; Send Work Group
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkGroup[$dataIndex], "AE" & $EWriteCount)
                        ; Send Department
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkDepartment, "AF" & $EWriteCount)
                        ; Send Supervisor
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Supervisors[$dataIndex], "AG" & $EWriteCount)
                        ; Send Notes
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkNotes[$dataIndex], "AH" & $EWriteCount)

                        ; Send Shift Number
                        $tempStime = StringReplace($StartTimes[$dataIndex], ":", "")
                        $tempEtime = StringReplace($EndTimes[$dataIndex], ":", "")
                        _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, "S " & $tempStime & "-" & $tempEtime, "AJ" & $EWriteCount)

                        $ACounter    += 1
                        $EWriteCount += 1

                        ConsoleWrite(@CRLF & "Saturday  " & $Temp & @CRLF)

                    EndIf
                Next

                $yesCount -= 1
                $tS = "N"

            Else
                ;Error Nothing equals "Y"
                ConsoleWrite(@CRLF & "Error Nothing equals 'Y'" & @CRLF)
            EndIf

            $DayIndex    += 1
            $LoopCount   += 1

        WEnd

        $Array_Index += 1
        $dataIndex   += 1
        $dCount      += 1

    WEnd

    MsgBox($MB_ICONINFORMATION, "Scheduler_Bot", "Finished Sending Data", 2)

EndFunc

 

Edited by nooneclose

Share this post


Link to post
Share on other sites

I figured it out here is a good chunk of the finished code:

#include <Array.au3>                                ; Allows arrays
#include <date.au3>                                 ; Allows Date functions
#include <Misc.au3>                                 ; Allows the "is pressed" function to be used
#include <MsgBoxConstants.au3>                      ; Allows message box to be used
#include <Excel.au3>                                ; Allows Excel functions
#include <File.au3>                                 ; Allows file manipulation
#include <Word.au3>                                 ; Allows certain word functions
#include <Constants.au3>                            ; Allows constants to be used
#include <StaticConstants.au3>                      ; Allows static constants
#include "ExtMsgBox.au3"                            ; Allows custom MsgBoxs

Global $WeekASunday                                 ; First Sunday of the Semester always week A
Global $WeekAMonday                                 ; First Monday of the Semester always week A
Global $WeekATuesday                                ; First Tuesday of the Semester always week A
Global $WeekAWednesday                              ; First Wednesday of the Semester always week A
Global $WeekAThursday                               ; First Thursday of the Semester always week A
Global $WeekAFriday                                 ; First Friday of the Semester always week A
Global $WeekASaturday                               ; First Saturday of the Semester always week A
Global $modResult = 9999999                         ; Is what the name suggests / Given crazy numbr for a reason - see line 1027-1833

Global $today = _NowDate()                          ; Gets todays (current) date



; Step 7
Func SendData()

    ;*******************************************************************************
    ; Sends all collected data to the Excel file in correct order for Upload
    ;*******************************************************************************
    MsgBox($MB_ICONINFORMATION, "Scheduler_Bot", "Sending Data", 2)

    ; Loop Counters
    $LoopCount   = 0
    $Array_Index = 0
    $DayIndex    = 0
    $dataIndex   = 0

    ; Counter for the day of the week
    Local $dCount = 2

    ; Counter for the numbers of Ys
    Local $yesCount = 0

    ; Excel Write Counter (VERY IMPORTANT!)
    Local $EWriteCount = 2

    ; Declare the global shift arrays (Sunday - Saturday)
    Global $ShiftDaySU[100][600]
    Global $ShiftDayM[100][600]
    Global $ShiftDayT[100][600]
    Global $ShiftDayW[100][600]
    Global $ShiftDayR[100][600]
    Global $ShiftDayF[100][600]
    Global $ShiftDayS[100][600]
    Global $sDates[400]

    While $Formatted_Names[$dataIndex] <> $Formatted_Names[$IndexRows] ; $LoopCount < $IndexRows

        $ACounter = 0 ; Array counter

        ; Gets the Start date from the array
        $Temp = $StartDate[$Array_Index]
        $TempStart = StringLeft($Temp, 8)
        $StartTempYear  = StringLeft($TempStart, 4)
        $StartTempMonth = StringMid($TempStart, 5, 2)
        $StartTempDay   = StringRight($TempStart, 2)

        ; Gets the End date from the array
        $Temp = $EndDate[$Array_Index]
        $TempEnd = StringLeft($Temp, 8)
        $EndTempYear  = StringLeft($TempEnd, 4)
        $EndTempMonth = StringMid($TempEnd, 5, 2)
        $EndTempDay   = StringRight($TempEnd, 2)

        ; The starting date (in value form)
        $sdate = _DateToDayValue($StartTempYear, $StartTempMonth, $StartTempDay)    ;_DateToDayValue(2019,1,9)
        ;ConsoleWrite(@CRLF & "$start date  " & $sdate & @CRLF & @CRLF)

        ; The ending date (in value form)
        $edate = _DateToDayValue($EndTempYear, $EndTempMonth, $EndTempDay)          ;_DateToDayValue(2019,4,9)
        ;ConsoleWrite(@CRLF & "$end date  " & $edate & @CRLF & @CRLF)

        ; Variables for readability
        Local $iYear, $iMonth, $iDay

        ;Stores what day of the week that shift lands on
        Local $tSU = _Excel_RangeRead($OpenWorkbook, Default, "I" & $dCount)
            If $tSU = "Y" Then
                $yesCount = 1
            EndIf
        Local $tM  = _Excel_RangeRead($OpenWorkbook, Default, "J" & $dCount)
            If $tM = "Y" Then
                $yesCount += 1
            EndIf
        Local $tT  = _Excel_RangeRead($OpenWorkbook, Default, "K" & $dCount)
            If $tT = "Y" Then
                $yesCount += 1
            EndIf
        Local $tW  = _Excel_RangeRead($OpenWorkbook, Default, "L" & $dCount)
            If $tW = "Y" Then
                $yesCount += 1
            EndIf
        Local $tR  = _Excel_RangeRead($OpenWorkbook, Default, "M" & $dCount)
            If $tR = "Y" Then
                $yesCount += 1
            EndIf
        Local $tF  = _Excel_RangeRead($OpenWorkbook, Default, "N" & $dCount)
            If $tF = "Y" Then
                $yesCount += 1
            EndIf
        Local $tS  = _Excel_RangeRead($OpenWorkbook, Default, "O" & $dCount)
            If $tS = "Y" Then
                $yesCount += 1
            EndIf

        ConsoleWrite(@CRLF & @CRLF)
        ConsoleWrite($tSU & @CRLF)
        ConsoleWrite($tM & @CRLF)
        ConsoleWrite($tT & @CRLF)
        ConsoleWrite($tW & @CRLF)
        ConsoleWrite($tR & @CRLF)
        ConsoleWrite($tF & @CRLF)
        ConsoleWrite($tS & @CRLF)
        ConsoleWrite(@CRLF & @CRLF)

        ; Check to see if they work every other week
        Local $rotationWeek  = _Excel_RangeRead($OpenWorkbook, Default, "U" & $dCount)
        Local $repeatWeek    = _Excel_RangeRead($OpenWorkbook, Default, "V" & $dCount)

        While $yesCount > 0

            If $tSU = "Y" Then
                If $repeatWeek = 1 Then
                    Local $MainLoopCount = 0
                    For $Index = $sdate To $edate
                        ; Send appropriate Work Shift dates $rotationWeek
                        ; Week A Shift
                        If $modResult = 0 And $MainLoopCount >= 1 Then
                            $Index += 1
                        ; Week B Shift
                        ElseIf $modResult <> 0 And $modResult <> 9999999 And $MainLoopCount >= 1 Then
                            $Index += 2
                        EndIf

                        _DayValueToDate($Index, $iYear, $iMonth, $iDay)
                        ; Finds the day based on its numerical value (1 = Sunday)
                        If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 1 Then
                            $Temp = $iYear & "-" & $iMonth & "-" & $iDay & "T" & "00" & ":" & "00" & ":" & "00" & ":" & "000"
                            $ShiftDaySU[$ACounter][$DayIndex] = $Temp
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $ShiftDaySU[$ACounter][$DayIndex], "AI" & $EWriteCount)

                            ; Send Name
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Formatted_Names[$dataIndex], "AA" & $EWriteCount)
                            ; Send Start Time
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $StartTimes[$dataIndex], "AB" & $EWriteCount)
                            ; Send End Time
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $EndTimes[$dataIndex], "AC" & $EWriteCount)
                            ; Send Work Hours
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $HoursWorked[$dataIndex], "AD" & $EWriteCount)
                            ; Send Work Group
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkGroup[$dataIndex], "AE" & $EWriteCount)
                            ; Send Department
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkDepartment, "AF" & $EWriteCount)
                            ; Send Supervisor
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Supervisors[$dataIndex], "AG" & $EWriteCount)
                            ; Send Notes
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkNotes[$dataIndex], "AH" & $EWriteCount)

                            ; Send Shift Number
                            $tempStime = StringReplace($StartTimes[$dataIndex], ":", "")
                            $tempEtime = StringReplace($EndTimes[$dataIndex], ":", "")
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, "SU " & $tempStime & "-" & $tempEtime, "AJ" & $EWriteCount)

                            $ACounter    += 1
                            $EWriteCount += 1

                            ConsoleWrite(@CRLF & "In Main loop: Sunday " & $Temp & @CRLF)

                        EndIf

                        $MainLoopCount += 1

                    Next

                    $yesCount -= 1
                    $tSU = "N"
                    $modResult = 9999999
                Else
                    Local $LoopCount = 0
                    ; Get first potential work day
                    For $Index = $sdate To $edate
                        _DayValueToDate($Index, $iYear, $iMonth, $iDay)
                        ; Finds the day based on its numerical value (1 = Sunday)

                        If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 1 Then
                            $TempFirstShift = $iYear & "/" & $iMonth & "/" & $iDay & " " & "00" & ":" & "00" & ":" & "00"
                        EndIf

                        ; Makes sure the For loop only loops once
                        If $LoopCount = 7 Then ExitLoop
                        $LoopCount += 1
                    Next

                    ConsoleWrite(@CRLF & "Week A Sunday " & $WeekASunday & @CRLF)
                    ConsoleWrite(@CRLF & "Potential first shift " & $TempFirstShift & @CRLF)

                    ; Use _Datediff
                    Local $iDateCalc = _DateDiff('D', $WeekASunday, $TempFirstShift)

                    ConsoleWrite(@CRLF & "Difference in days is " & $iDateCalc & @CRLF)

                    ; Use Mod
                    $modResult = Mod($iDateCalc, 14)
                    ConsoleWrite(@CRLF & "Mod Result " & $modResult & @CRLF)

                    ; check to see if it is suppose to be week a or week b
                    If $rotationWeek = 1 And $modResult = 0 Then
                        ; Keep going as planned
                    ElseIf $rotationWeek = 2 And $modResult = 0 Then
                        ; Something strange is in the neighborhood
                        $TempDateHolder = _DateAdd('d', 7, $TempFirstShift)

                        ConsoleWrite(@CRLF & "Correct First Shift " & $TempDateHolder & @CRLF)
                        ConsoleWrite(@CRLF & "Start date " & $sdate & @CRLF)

                        $tempStartDate = StringReplace($TempDateHolder, "/", "")

                        ; Gets the Start date from the array
                        $TempSD = $tempStartDate
                        $Temp_Start = StringLeft($TempSD, 8)
                        $Start_TempYear  = StringLeft($Temp_Start, 4)
                        $Start_TempMonth = StringMid($Temp_Start, 5, 2)
                        $Start_TempDay   = StringRight($Temp_Start, 2)

                        $sdate = _DateToDayValue($Start_TempYear, $Start_TempMonth, $Start_TempDay)
                        ConsoleWrite(@CRLF & @CRLF & "Start date After change " & $sdate & @CRLF & @CRLF)

                    EndIf
                    ; Set repeat week = 1 so the main loop will send the new dates
                    $repeatWeek = 1
                EndIf

            ElseIf $tM = "Y" Then
                If $repeatWeek = 1 Then
                    Local $MainLoopCount = 0
                    For $Index = $sdate To $edate
                        ; Send appropriate Work Shift dates $rotationWeek
                        ; Week A Shift
                        If $modResult = 0 And $MainLoopCount >= 1 Then
                            $Index += 1
                        ; Week B Shift
                        ElseIf $modResult <> 0 And $modResult <> 9999999 And $MainLoopCount >= 1 Then
                            $Index += 2
                        EndIf

                        _DayValueToDate($Index, $iYear, $iMonth, $iDay)
                        ; Finds the day based on its numerical value (1 = Sunday)
                        If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 2 Then
                            $Temp = $iYear & "-" & $iMonth & "-" & $iDay & "T" & "00" & ":" & "00" & ":" & "00" & ":" & "000"
                            $ShiftDayM[$ACounter][$DayIndex] = $Temp
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $ShiftDayM[$ACounter][$DayIndex], "AI" & $EWriteCount)

                            ; Send Name
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Formatted_Names[$dataIndex], "AA" & $EWriteCount)
                            ; Send Start Time
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $StartTimes[$dataIndex], "AB" & $EWriteCount)
                            ; Send End Time
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $EndTimes[$dataIndex], "AC" & $EWriteCount)
                            ; Send Work Hours
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $HoursWorked[$dataIndex], "AD" & $EWriteCount)
                            ; Send Work Group
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkGroup[$dataIndex], "AE" & $EWriteCount)
                            ; Send Department
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkDepartment, "AF" & $EWriteCount)
                            ; Send Supervisor
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Supervisors[$dataIndex], "AG" & $EWriteCount)
                            ; Send Notes
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkNotes[$dataIndex], "AH" & $EWriteCount)

                            ; Send Shift Number
                            $tempStime = StringReplace($StartTimes[$dataIndex], ":", "")
                            $tempEtime = StringReplace($EndTimes[$dataIndex], ":", "")
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, "M " & $tempStime & "-" & $tempEtime, "AJ" & $EWriteCount)

                            $ACounter    += 1
                            $EWriteCount += 1

                            ConsoleWrite(@CRLF & "In Main loop: Monday " & $Temp & @CRLF)

                        EndIf

                        $MainLoopCount += 1

                    Next

                    $yesCount -= 1
                    $tM = "N"
                    $modResult = 9999999
                Else
                    Local $LoopCount = 0
                    ; Get first potential work day
                    For $Index = $sdate To $edate
                        _DayValueToDate($Index, $iYear, $iMonth, $iDay)
                        ; Finds the day based on its numerical value (1 = Sunday)

                        If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 2 Then
                            $TempFirstShift = $iYear & "/" & $iMonth & "/" & $iDay & " " & "00" & ":" & "00" & ":" & "00"
                        EndIf

                        ; Makes sure the For loop only loops once
                        If $LoopCount = 7 Then ExitLoop
                        $LoopCount += 1
                    Next

                    ConsoleWrite(@CRLF & "Week A Monday " & $WeekAMonday & @CRLF)
                    ConsoleWrite(@CRLF & "Potential first shift " & $TempFirstShift & @CRLF)

                    ; Use _Datediff
                    Local $iDateCalc = _DateDiff('D', $WeekAMonday, $TempFirstShift)

                    ConsoleWrite(@CRLF & "Difference in days is " & $iDateCalc & @CRLF)

                    ; Use Mod
                    $modResult = Mod($iDateCalc, 14)
                    ConsoleWrite(@CRLF & "Mod Result " & $modResult & @CRLF)

                    ; check to see if it is suppose to be week a or week b
                    If $rotationWeek = 1 And $modResult = 0 Then
                        ; Keep going as planned
                    ElseIf $rotationWeek = 2 And $modResult = 0 Then
                        ; Something strange is in the neighborhood
                        $TempDateHolder = _DateAdd('d', 7, $TempFirstShift)

                        ConsoleWrite(@CRLF & "Correct First Shift " & $TempDateHolder & @CRLF)
                        ConsoleWrite(@CRLF & "Start date " & $sdate & @CRLF)

                        $tempStartDate = StringReplace($TempDateHolder, "/", "")

                        ; Gets the Start date from the array
                        $TempSD = $tempStartDate
                        $Temp_Start = StringLeft($TempSD, 8)
                        $Start_TempYear  = StringLeft($Temp_Start, 4)
                        $Start_TempMonth = StringMid($Temp_Start, 5, 2)
                        $Start_TempDay   = StringRight($Temp_Start, 2)

                        $sdate = _DateToDayValue($Start_TempYear, $Start_TempMonth, $Start_TempDay)
                        ConsoleWrite(@CRLF & @CRLF & "Start date After change " & $sdate & @CRLF & @CRLF)

                    EndIf
                    ; Set repeat week = 1 so the main loop will send the new dates
                    $repeatWeek = 1
                EndIf

            ElseIf $tT = "Y" Then
                If $repeatWeek = 1 Then
                    Local $MainLoopCount = 0
                    For $Index = $sdate To $edate
                        ; Send appropriate Work Shift dates $rotationWeek
                        ; Week A Shift
                        If $modResult = 0 And $MainLoopCount >= 1 Then
                            $Index += 1
                        ; Week B Shift
                        ElseIf $modResult <> 0 And $modResult <> 9999999 And $MainLoopCount >= 1 Then
                            $Index += 2
                        EndIf

                        _DayValueToDate($Index, $iYear, $iMonth, $iDay)
                        ; Finds the day based on its numerical value (1 = Sunday)
                        If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 3 Then
                            $Temp = $iYear & "-" & $iMonth & "-" & $iDay & "T" & "00" & ":" & "00" & ":" & "00" & ":" & "000"
                            $ShiftDayT[$ACounter][$DayIndex] = $Temp
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $ShiftDayT[$ACounter][$DayIndex], "AI" & $EWriteCount)

                            ; Send Name
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Formatted_Names[$dataIndex], "AA" & $EWriteCount)
                            ; Send Start Time
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $StartTimes[$dataIndex], "AB" & $EWriteCount)
                            ; Send End Time
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $EndTimes[$dataIndex], "AC" & $EWriteCount)
                            ; Send Work Hours
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $HoursWorked[$dataIndex], "AD" & $EWriteCount)
                            ; Send Work Group
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkGroup[$dataIndex], "AE" & $EWriteCount)
                            ; Send Department
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkDepartment, "AF" & $EWriteCount)
                            ; Send Supervisor
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Supervisors[$dataIndex], "AG" & $EWriteCount)
                            ; Send Notes
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkNotes[$dataIndex], "AH" & $EWriteCount)

                            ; Send Shift Number
                            $tempStime = StringReplace($StartTimes[$dataIndex], ":", "")
                            $tempEtime = StringReplace($EndTimes[$dataIndex], ":", "")
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, "T " & $tempStime & "-" & $tempEtime, "AJ" & $EWriteCount)

                            $ACounter    += 1
                            $EWriteCount += 1

                            ConsoleWrite(@CRLF & "In Main loop: Tuesday " & $Temp & @CRLF)

                        EndIf

                        $MainLoopCount += 1

                    Next

                    $yesCount -= 1
                    $tT = "N"
                    $modResult = 9999999
                Else
                    Local $LoopCount = 0
                    ; Get first potential work day
                    For $Index = $sdate To $edate
                        _DayValueToDate($Index, $iYear, $iMonth, $iDay)
                        ; Finds the day based on its numerical value (1 = Sunday)

                        If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 3 Then
                            $TempFirstShift = $iYear & "/" & $iMonth & "/" & $iDay & " " & "00" & ":" & "00" & ":" & "00"
                        EndIf

                        ; Makes sure the For loop only loops once
                        If $LoopCount = 7 Then ExitLoop
                        $LoopCount += 1
                    Next

                    ConsoleWrite(@CRLF & "Week A Tuesday " & $WeekATuesday & @CRLF)
                    ConsoleWrite(@CRLF & "Potential first shift " & $TempFirstShift & @CRLF)

                    ; Use _Datediff
                    Local $iDateCalc = _DateDiff('D', $WeekATuesday, $TempFirstShift)

                    ConsoleWrite(@CRLF & "Difference in days is " & $iDateCalc & @CRLF)

                    ; Use Mod
                    $modResult = Mod($iDateCalc, 14)
                    ConsoleWrite(@CRLF & "Mod Result " & $modResult & @CRLF)

                    ; check to see if it is suppose to be week a or week b
                    If $rotationWeek = 1 And $modResult = 0 Then
                        ; Keep going as planned
                    ElseIf $rotationWeek = 2 And $modResult = 0 Then
                        ; Something strange is in the neighborhood
                        $TempDateHolder = _DateAdd('d', 7, $TempFirstShift)

                        ConsoleWrite(@CRLF & "Correct First Shift " & $TempDateHolder & @CRLF)
                        ConsoleWrite(@CRLF & "Start date " & $sdate & @CRLF)

                        $tempStartDate = StringReplace($TempDateHolder, "/", "")

                        ; Gets the Start date from the array
                        $TempSD = $tempStartDate
                        $Temp_Start = StringLeft($TempSD, 8)
                        $Start_TempYear  = StringLeft($Temp_Start, 4)
                        $Start_TempMonth = StringMid($Temp_Start, 5, 2)
                        $Start_TempDay   = StringRight($Temp_Start, 2)

                        $sdate = _DateToDayValue($Start_TempYear, $Start_TempMonth, $Start_TempDay)
                        ConsoleWrite(@CRLF & @CRLF & "Start date After change " & $sdate & @CRLF & @CRLF)

                    EndIf
                    ; Set repeat week = 1 so the main loop will send the new dates
                    $repeatWeek = 1
                EndIf

            ElseIf $tW = "Y" Then
                If $repeatWeek = 1 Then
                    Local $MainLoopCount = 0
                    For $Index = $sdate To $edate
                        ; Send appropriate Work Shift dates $rotationWeek
                        ; Week A Shift
                        If $modResult = 0 And $MainLoopCount >= 1 Then
                            $Index += 1
                        ; Week B Shift
                        ElseIf $modResult <> 0 And $modResult <> 9999999 And $MainLoopCount >= 1 Then
                            $Index += 2
                        EndIf

                        _DayValueToDate($Index, $iYear, $iMonth, $iDay)
                        ; Finds the day based on its numerical value (1 = Sunday)
                        If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 4 Then
                            $Temp = $iYear & "-" & $iMonth & "-" & $iDay & "T" & "00" & ":" & "00" & ":" & "00" & ":" & "000"
                            $ShiftDayW[$ACounter][$DayIndex] = $Temp
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $ShiftDayW[$ACounter][$DayIndex], "AI" & $EWriteCount)

                            ; Send Name
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Formatted_Names[$dataIndex], "AA" & $EWriteCount)
                            ; Send Start Time
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $StartTimes[$dataIndex], "AB" & $EWriteCount)
                            ; Send End Time
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $EndTimes[$dataIndex], "AC" & $EWriteCount)
                            ; Send Work Hours
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $HoursWorked[$dataIndex], "AD" & $EWriteCount)
                            ; Send Work Group
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkGroup[$dataIndex], "AE" & $EWriteCount)
                            ; Send Department
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkDepartment, "AF" & $EWriteCount)
                            ; Send Supervisor
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Supervisors[$dataIndex], "AG" & $EWriteCount)
                            ; Send Notes
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkNotes[$dataIndex], "AH" & $EWriteCount)

                            ; Send Shift Number
                            $tempStime = StringReplace($StartTimes[$dataIndex], ":", "")
                            $tempEtime = StringReplace($EndTimes[$dataIndex], ":", "")
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, "W " & $tempStime & "-" & $tempEtime, "AJ" & $EWriteCount)

                            $ACounter    += 1
                            $EWriteCount += 1

                            ConsoleWrite(@CRLF & "In Main loop: Wednesday " & $Temp & @CRLF)

                        EndIf

                        $MainLoopCount += 1

                    Next

                    $yesCount -= 1
                    $tW = "N"
                    $modResult = 9999999
                Else
                    Local $LoopCount = 0
                    ; Get first potential work day
                    For $Index = $sdate To $edate
                        _DayValueToDate($Index, $iYear, $iMonth, $iDay)
                        ; Finds the day based on its numerical value (1 = Sunday)

                        If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 4 Then
                            $TempFirstShift = $iYear & "/" & $iMonth & "/" & $iDay & " " & "00" & ":" & "00" & ":" & "00"
                        EndIf

                        ; Makes sure the For loop only loops once
                        If $LoopCount = 7 Then ExitLoop
                        $LoopCount += 1
                    Next

                    ConsoleWrite(@CRLF & "Week A Wednesday " & $WeekAWednesday & @CRLF)
                    ConsoleWrite(@CRLF & "Potential first shift " & $TempFirstShift & @CRLF)

                    ; Use _Datediff
                    Local $iDateCalc = _DateDiff('D', $WeekAWednesday, $TempFirstShift)

                    ConsoleWrite(@CRLF & "Difference in days is " & $iDateCalc & @CRLF)

                    ; Use Mod
                    $modResult = Mod($iDateCalc, 14)
                    ConsoleWrite(@CRLF & "Mod Result " & $modResult & @CRLF)

                    ; check to see if it is suppose to be week a or week b
                    If $rotationWeek = 1 And $modResult = 0 Then
                        ; Keep going as planned
                    ElseIf $rotationWeek = 2 And $modResult = 0 Then
                        ; Something strange is in the neighborhood
                        $TempDateHolder = _DateAdd('d', 7, $TempFirstShift)

                        ConsoleWrite(@CRLF & "Correct First Shift " & $TempDateHolder & @CRLF)
                        ConsoleWrite(@CRLF & "Start date " & $sdate & @CRLF)

                        $tempStartDate = StringReplace($TempDateHolder, "/", "")

                        ; Gets the Start date from the array
                        $TempSD = $tempStartDate
                        $Temp_Start = StringLeft($TempSD, 8)
                        $Start_TempYear  = StringLeft($Temp_Start, 4)
                        $Start_TempMonth = StringMid($Temp_Start, 5, 2)
                        $Start_TempDay   = StringRight($Temp_Start, 2)

                        $sdate = _DateToDayValue($Start_TempYear, $Start_TempMonth, $Start_TempDay)
                        ConsoleWrite(@CRLF & @CRLF & "Start date After change " & $sdate & @CRLF & @CRLF)

                    EndIf
                    ; Set repeat week = 1 so the main loop will send the new dates
                    $repeatWeek = 1
                EndIf

            ElseIf $tR = "Y" Then
                If $repeatWeek = 1 Then
                    Local $MainLoopCount = 0
                    For $Index = $sdate To $edate
                        ; Send appropriate Work Shift dates $rotationWeek
                        ; Week A Shift
                        If $modResult = 0 And $MainLoopCount >= 1 Then
                            $Index += 1
                        ; Week B Shift
                        ElseIf $modResult <> 0 And $modResult <> 9999999 And $MainLoopCount >= 1 Then
                            $Index += 2
                        EndIf

                        _DayValueToDate($Index, $iYear, $iMonth, $iDay)
                        ; Finds the day based on its numerical value (1 = Sunday)
                        If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 5 Then
                            $Temp = $iYear & "-" & $iMonth & "-" & $iDay & "T" & "00" & ":" & "00" & ":" & "00" & ":" & "000"
                            $ShiftDayR[$ACounter][$DayIndex] = $Temp
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $ShiftDayR[$ACounter][$DayIndex], "AI" & $EWriteCount)

                            ; Send Name
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Formatted_Names[$dataIndex], "AA" & $EWriteCount)
                            ; Send Start Time
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $StartTimes[$dataIndex], "AB" & $EWriteCount)
                            ; Send End Time
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $EndTimes[$dataIndex], "AC" & $EWriteCount)
                            ; Send Work Hours
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $HoursWorked[$dataIndex], "AD" & $EWriteCount)
                            ; Send Work Group
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkGroup[$dataIndex], "AE" & $EWriteCount)
                            ; Send Department
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkDepartment, "AF" & $EWriteCount)
                            ; Send Supervisor
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Supervisors[$dataIndex], "AG" & $EWriteCount)
                            ; Send Notes
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkNotes[$dataIndex], "AH" & $EWriteCount)

                            ; Send Shift Number
                            $tempStime = StringReplace($StartTimes[$dataIndex], ":", "")
                            $tempEtime = StringReplace($EndTimes[$dataIndex], ":", "")
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, "R " & $tempStime & "-" & $tempEtime, "AJ" & $EWriteCount)

                            $ACounter    += 1
                            $EWriteCount += 1

                            ConsoleWrite(@CRLF & "In Main loop: Thursday " & $Temp & @CRLF)

                        EndIf

                        $MainLoopCount += 1

                    Next

                    $yesCount -= 1
                    $tR = "N"
                    $modResult = 9999999
                Else
                    Local $LoopCount = 0
                    ; Get first potential work day
                    For $Index = $sdate To $edate
                        _DayValueToDate($Index, $iYear, $iMonth, $iDay)
                        ; Finds the day based on its numerical value (1 = Sunday)

                        If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 5 Then
                            $TempFirstShift = $iYear & "/" & $iMonth & "/" & $iDay & " " & "00" & ":" & "00" & ":" & "00"
                        EndIf

                        ; Makes sure the For loop only loops once
                        If $LoopCount = 7 Then ExitLoop
                        $LoopCount += 1
                    Next

                    ConsoleWrite(@CRLF & "Week A Thursday " & $WeekAThursday & @CRLF)
                    ConsoleWrite(@CRLF & "Potential first shift " & $TempFirstShift & @CRLF)

                    ; Use _Datediff
                    Local $iDateCalc = _DateDiff('D', $WeekAThursday, $TempFirstShift)

                    ConsoleWrite(@CRLF & "Difference in days is " & $iDateCalc & @CRLF)

                    ; Use Mod
                    $modResult = Mod($iDateCalc, 14)
                    ConsoleWrite(@CRLF & "Mod Result " & $modResult & @CRLF)

                    ; check to see if it is suppose to be week a or week b
                    If $rotationWeek = 1 And $modResult = 0 Then
                        ; Keep going as planned
                    ElseIf $rotationWeek = 2 And $modResult = 0 Then
                        ; Something strange is in the neighborhood
                        $TempDateHolder = _DateAdd('d', 7, $TempFirstShift)

                        ConsoleWrite(@CRLF & "Correct First Shift " & $TempDateHolder & @CRLF)
                        ConsoleWrite(@CRLF & "Start date " & $sdate & @CRLF)

                        $tempStartDate = StringReplace($TempDateHolder, "/", "")

                        ; Gets the Start date from the array
                        $TempSD = $tempStartDate
                        $Temp_Start = StringLeft($TempSD, 8)
                        $Start_TempYear  = StringLeft($Temp_Start, 4)
                        $Start_TempMonth = StringMid($Temp_Start, 5, 2)
                        $Start_TempDay   = StringRight($Temp_Start, 2)

                        $sdate = _DateToDayValue($Start_TempYear, $Start_TempMonth, $Start_TempDay)
                        ConsoleWrite(@CRLF & @CRLF & "Start date After change " & $sdate & @CRLF & @CRLF)

                    EndIf
                    ; Set repeat week = 1 so the main loop will send the new dates
                    $repeatWeek = 1
                EndIf

            ElseIf $tF = "Y" Then
                If $repeatWeek = 1 Then
                    Local $MainLoopCount = 0
                    For $Index = $sdate To $edate
                        ; Send appropriate Work Shift dates $rotationWeek
                        ; Week A Shift
                        If $modResult = 0 And $MainLoopCount >= 1 Then
                            $Index += 1
                        ; Week B Shift
                        ElseIf $modResult <> 0 And $modResult <> 9999999 And $MainLoopCount >= 1 Then
                            $Index += 2
                        EndIf

                        _DayValueToDate($Index, $iYear, $iMonth, $iDay)
                        ; Finds the day based on its numerical value (1 = Sunday)
                        If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 6 Then
                            $Temp = $iYear & "-" & $iMonth & "-" & $iDay & "T" & "00" & ":" & "00" & ":" & "00" & ":" & "000"
                            $ShiftDayF[$ACounter][$DayIndex] = $Temp
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $ShiftDayF[$ACounter][$DayIndex], "AI" & $EWriteCount)

                            ; Send Name
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Formatted_Names[$dataIndex], "AA" & $EWriteCount)
                            ; Send Start Time
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $StartTimes[$dataIndex], "AB" & $EWriteCount)
                            ; Send End Time
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $EndTimes[$dataIndex], "AC" & $EWriteCount)
                            ; Send Work Hours
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $HoursWorked[$dataIndex], "AD" & $EWriteCount)
                            ; Send Work Group
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkGroup[$dataIndex], "AE" & $EWriteCount)
                            ; Send Department
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkDepartment, "AF" & $EWriteCount)
                            ; Send Supervisor
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Supervisors[$dataIndex], "AG" & $EWriteCount)
                            ; Send Notes
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkNotes[$dataIndex], "AH" & $EWriteCount)

                            ; Send Shift Number
                            $tempStime = StringReplace($StartTimes[$dataIndex], ":", "")
                            $tempEtime = StringReplace($EndTimes[$dataIndex], ":", "")
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, "F " & $tempStime & "-" & $tempEtime, "AJ" & $EWriteCount)

                            $ACounter    += 1
                            $EWriteCount += 1

                            ConsoleWrite(@CRLF & "In Main loop: Friday " & $Temp & @CRLF)

                        EndIf

                        $MainLoopCount += 1

                    Next

                    $yesCount -= 1
                    $tF = "N"
                    $modResult = 9999999
                Else
                    Local $LoopCount = 0
                    ; Get first potential work day
                    For $Index = $sdate To $edate
                        _DayValueToDate($Index, $iYear, $iMonth, $iDay)
                        ; Finds the day based on its numerical value (1 = Sunday)

                        If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 6 Then
                            $TempFirstShift = $iYear & "/" & $iMonth & "/" & $iDay & " " & "00" & ":" & "00" & ":" & "00"
                        EndIf

                        ; Makes sure the For loop only loops once
                        If $LoopCount = 7 Then ExitLoop
                        $LoopCount += 1
                    Next

                    ConsoleWrite(@CRLF & "Week A Friday " & $WeekAFriday & @CRLF)
                    ConsoleWrite(@CRLF & "Potential first shift " & $TempFirstShift & @CRLF)

                    ; Use _Datediff
                    Local $iDateCalc = _DateDiff('D', $WeekAFriday, $TempFirstShift)

                    ConsoleWrite(@CRLF & "Difference in days is " & $iDateCalc & @CRLF)

                    ; Use Mod
                    $modResult = Mod($iDateCalc, 14)
                    ConsoleWrite(@CRLF & "Mod Result " & $modResult & @CRLF)

                    ; check to see if it is suppose to be week a or week b
                    If $rotationWeek = 1 And $modResult = 0 Then
                        ; Keep going as planned
                    ElseIf $rotationWeek = 2 And $modResult = 0 Then
                        ; Something strange is in the neighborhood
                        $TempDateHolder = _DateAdd('d', 7, $TempFirstShift)

                        ConsoleWrite(@CRLF & "Correct First Shift " & $TempDateHolder & @CRLF)
                        ConsoleWrite(@CRLF & "Start date " & $sdate & @CRLF)

                        $tempStartDate = StringReplace($TempDateHolder, "/", "")

                        ; Gets the Start date from the array
                        $TempSD = $tempStartDate
                        $Temp_Start = StringLeft($TempSD, 8)
                        $Start_TempYear  = StringLeft($Temp_Start, 4)
                        $Start_TempMonth = StringMid($Temp_Start, 5, 2)
                        $Start_TempDay   = StringRight($Temp_Start, 2)

                        $sdate = _DateToDayValue($Start_TempYear, $Start_TempMonth, $Start_TempDay)
                        ConsoleWrite(@CRLF & @CRLF & "Start date After change " & $sdate & @CRLF & @CRLF)

                    EndIf
                    ; Set repeat week = 1 so the main loop will send the new dates
                    $repeatWeek = 1
                EndIf

            ElseIf $tS = "Y" Then
                If $repeatWeek = 1 Then
                    Local $MainLoopCount = 0
                    For $Index = $sdate To $edate
                        ; Send appropriate Work Shift dates $rotationWeek
                        ; Week A Shift
                        If $modResult = 0 And $MainLoopCount >= 1 Then
                            $Index += 1
                        ; Week B Shift
                        ElseIf $modResult <> 0 And $modResult <> 9999999 And $MainLoopCount >= 1 Then
                            $Index += 2
                        EndIf

                        _DayValueToDate($Index, $iYear, $iMonth, $iDay)
                        ; Finds the day based on its numerical value (1 = Sunday)
                        If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 7 Then
                            $Temp = $iYear & "-" & $iMonth & "-" & $iDay & "T" & "00" & ":" & "00" & ":" & "00" & ":" & "000"
                            $ShiftDayS[$ACounter][$DayIndex] = $Temp
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $ShiftDayS[$ACounter][$DayIndex], "AI" & $EWriteCount)

                            ; Send Name
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Formatted_Names[$dataIndex], "AA" & $EWriteCount)
                            ; Send Start Time
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $StartTimes[$dataIndex], "AB" & $EWriteCount)
                            ; Send End Time
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $EndTimes[$dataIndex], "AC" & $EWriteCount)
                            ; Send Work Hours
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $HoursWorked[$dataIndex], "AD" & $EWriteCount)
                            ; Send Work Group
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkGroup[$dataIndex], "AE" & $EWriteCount)
                            ; Send Department
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkDepartment, "AF" & $EWriteCount)
                            ; Send Supervisor
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $Supervisors[$dataIndex], "AG" & $EWriteCount)
                            ; Send Notes
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $WorkNotes[$dataIndex], "AH" & $EWriteCount)

                            ; Send Shift Number
                            $tempStime = StringReplace($StartTimes[$dataIndex], ":", "")
                            $tempEtime = StringReplace($EndTimes[$dataIndex], ":", "")
                            _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, "S " & $tempStime & "-" & $tempEtime, "AJ" & $EWriteCount)

                            $ACounter    += 1
                            $EWriteCount += 1

                            ConsoleWrite(@CRLF & "In Main loop: Saturday " & $Temp & @CRLF)

                        EndIf

                        $MainLoopCount += 1

                    Next

                    $yesCount -= 1
                    $tS = "N"
                    $modResult = 9999999
                Else
                    Local $LoopCount = 0
                    ; Get first potential work day
                    For $Index = $sdate To $edate
                        _DayValueToDate($Index, $iYear, $iMonth, $iDay)
                        ; Finds the day based on its numerical value (1 = Sunday)

                        If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 7 Then
                            $TempFirstShift = $iYear & "/" & $iMonth & "/" & $iDay & " " & "00" & ":" & "00" & ":" & "00"
                        EndIf

                        ; Makes sure the For loop only loops once
                        If $LoopCount = 7 Then ExitLoop
                        $LoopCount += 1
                    Next

                    ConsoleWrite(@CRLF & "Week A Saturday " & $WeekASaturday & @CRLF)
                    ConsoleWrite(@CRLF & "Potential first shift " & $TempFirstShift & @CRLF)

                    ; Use _Datediff
                    Local $iDateCalc = _DateDiff('D', $WeekASaturday, $TempFirstShift)

                    ConsoleWrite(@CRLF & "Difference in days is " & $iDateCalc & @CRLF)

                    ; Use Mod
                    $modResult = Mod($iDateCalc, 14)
                    ConsoleWrite(@CRLF & "Mod Result " & $modResult & @CRLF)

                    ; check to see if it is suppose to be week a or week b
                    If $rotationWeek = 1 And $modResult = 0 Then
                        ; Keep going as planned
                    ElseIf $rotationWeek = 2 And $modResult = 0 Then
                        ; Something strange is in the neighborhood
                        $TempDateHolder = _DateAdd('d', 7, $TempFirstShift)

                        ConsoleWrite(@CRLF & "Correct First Shift " & $TempDateHolder & @CRLF)
                        ConsoleWrite(@CRLF & "Start date " & $sdate & @CRLF)

                        $tempStartDate = StringReplace($TempDateHolder, "/", "")

                        ; Gets the Start date from the array
                        $TempSD = $tempStartDate
                        $Temp_Start = StringLeft($TempSD, 8)
                        $Start_TempYear  = StringLeft($Temp_Start, 4)
                        $Start_TempMonth = StringMid($Temp_Start, 5, 2)
                        $Start_TempDay   = StringRight($Temp_Start, 2)

                        $sdate = _DateToDayValue($Start_TempYear, $Start_TempMonth, $Start_TempDay)
                        ConsoleWrite(@CRLF & @CRLF & "Start date After change " & $sdate & @CRLF & @CRLF)

                    EndIf
                    ; Set repeat week = 1 so the main loop will send the new dates
                    $repeatWeek = 1
                EndIf
            Else
                ;Error Nothing equals "Y"
                ConsoleWrite(@CRLF & "Error Nothing equals 'Y'" & @CRLF)
            EndIf

            $DayIndex    += 1
            $LoopCount   += 1

        WEnd

        $Array_Index += 1
        $dataIndex   += 1
        $dCount      += 1

    WEnd

    MsgBox($MB_ICONINFORMATION, "Scheduler_Bot", "Finished Sending Data", 2)

EndFunc

 

Share this post


Link to post
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

  • Similar Content

    • By VinMe
      Dear all, 
      I am unable to get the right result after applying the filter to the excel. please let me know on the same.
      issue: After applying the filter the output $lastRow11 not giving the right output of complete visible rows. (its breaking at row skips)
       
      ;DATA EXTRACTION FROM LOC EXCEL
      ;=============================================================================
      $oWorkbook = _Excel_BookAttach($sWorkbook)
      Local $sMSN = InputBox("MSN NO", "Enter MSN in XX FORMAT", "")
      ;~ Local $LastRow1 = ($oWorkbook.ACTIVESHEET.Range("A1").SpecialCells($xlCellTypeLastCell).Row)
      $LastRow1 = $oWorkbook.ActiveSheet.UsedRange.Rows.Count
      MsgBox(0, "lastrow1", $LastRow1)
      _Excel_FilterSet($oWorkbook, $oWorkbook.activesheet, "AF1", 32, "*" & $sMSN & "*")
      Local $oLocDS = $oWorkbook.ActiveSheet.Range("S1:S" & $LastRow1).SpecialCells($xlCellTypeVisible)
      Local $LastRow11 = $oLocDS.rows.count    ;error output
      MsgBox(0, "lastrow11", $LastRow11)
      Local $aLocDS1 = _Excel_RangeRead($oWorkbook, Default, $oLocDS)
      Local $oLocNr = $oWorkbook.ActiveSheet.Range("A1:A" & $LastRow1).SpecialCells($xlCellTypeVisible)
      Local $aLocNr1 = _Excel_RangeRead($oWorkbook, Default, $oLocNr)
      _ArrayDisplay($aLocDS1)
      _ArrayDisplay($aLocNr1)
      _ArrayTrim($aLocDS1, 6, 1)
      _ArrayTrim($aLocNr1, 6, 1)
      _ArrayTrim($aLocNr1, 6, 0)
      _ArrayDisplay($aLocDS1)
      _ArrayDisplay($aLocNr1)
    • By plankton
      Hi I want it to search for a specific color in certain area then excute the loop which presses ESC button and stop the loop when the color no longer present in that specific area.  Here is the example of my code. But it doesnt stop when color is disappeared.
       
      Pixelsearch(511, 455, 678, 501, 0xFFFFFF)
      If Not  @Error Then
      While 1
      Sleep(1000)
      Send("{ESC}")
      Pixelsearch(511, 455, 678, 501, 0xFFFFFF)
      If @Error Then Exitloop
       
    • By nooneclose
      Good morning, I have been thinking about trying to make my Autoit script run in the background. I found out today that it is impossible due to the UIA and mouseclick functions that I use. However, while reading other posts about running Autoit scripts in the background I saw a reply mentioning how a script like mine might be able to run on a VM while still giving me the ability to work on my Host OS. Can someone confirm this? 
      Here is a link to the thread where I saw VM mentioned. 
      the person who mentioned it was @ViciousXUSMC 
    • By VinMe
      I am unable to execute the below script, my requirement is to copy the content from active excel sheet and to display the same.
      Please let me know where i am missing!
      #include <Excel.au3>
      #include <MsgBoxConstants.au3>
      #include <Array.au3>
      #include <StringConstants.au3>
      Local $oExcel = _Excel_Open()
      $LastRow2 = $oExcel.UsedRange.Rows.Count
      $Tissue = _Excel_RangeRead($oExcel, Default, "E1:E" & $LastRow2)
      $TshNr = _Excel_RangeRead($oExcel, Default, "F1:F" & $LastRow2)
      _ArrayDisplay($Tissue)
      _ArrayDisplay($TshNr)
    • By nooneclose
      Good morning, all. I am having a very hard time figuring out why my code "breaks" every second (and every time after) iteration in the loop. 
      I am trying to automate the process of filling out a form for work. I need to find and send data to seven fields and get data from one field. 
      Here are a couple of pictures of the fields I am interacting with. The fields are on the same forum/page. (the green boxed ones)
       


      Here is my code so far. 
       
      #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ;Allows for the combining of UDFs by disabling error messages. (I get error messages for "problems" that dont actually exsist) #include <AD.au3> ;Allows Active Directory functions #include <Array.au3> ;Allows special Array functions #include <Constants.au3> ;Allows constants to be used #include <Date.au3> ;Allows Date and Time functions #include <DateTimeConstants.au3> ;Allows Date and Time constant functions #include "DTC.au3" ;Allows Custom Date and Time functions #include <IE.au3> ;Allows Internet Explorer functions #include <Misc.au3> ;Allows the "is pressed" function to be used #include <MsgBoxConstants.au3> ;Allows Message box function to be used #include <OutlookEX.au3> ;Allows the Outlook functions #include <String.au3> ;Allows special string functions #include <StringConstants.au3> ;Allows String constant functions #include <Timers.au3> ;Allows timer functions ;#RequireAdmin ;Requests admin privliges before starting program ; Special UDFs for UIA automation #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <debug.au3> #include <WinAPI.au3> #include "UIAWrappers.au3" #AutoIt3Wrapper_UseX64=N ;Should be used for stuff like tagpoint having right struct etc. when running on a 64 bits os ;******************************************************************************* ; Format and send the vaild E-mail's contents ;******************************************************************************* Func SendEmailData() ConsoleWrite("Action 16: Send E-mail Data to it's proper fields" & " at line: " & @ScriptLineNumber & @CRLF) ;=============================================================================== ; Store the Elements ;=============================================================================== ; Description _UIA_setVar("oDescription","Title:=Description:;controltype:=UIA_EditControlTypeId;class:=") ; Long Description OK Button _UIA_setVar("oLongButton","Title:=Long Description;controltype:=UIA_ImageControlTypeId;class:=") _UIA_setVar("oLongOk","Title:=OK;controltype:=UIA_ButtonControlTypeId;class:=") ; Work Order Number _UIA_setVar("oWorkOrderNum","Title:=Work Order:;controltype:=UIA_EditControlTypeId;class:=") ; Location _UIA_setVar("oLocation","Title:=Location:;controltype:=UIA_EditControlTypeId;class:=") ; Work Type _UIA_setVar("oWorkType","Title:=Work Type:;controltype:=UIA_EditControlTypeId;class:=") ; Reported By Date _UIA_setVar("oDate","Title:=Reported Date:;controltype:=UIA_EditControlTypeId;class:=") ; Reported By Person _UIA_setVar("oCustomer","Title:=Reported By:;controltype:=UIA_EditControlTypeId;class:=") ; Reported By Email _UIA_setVar("oEmail","Title:=Reported By Email:;controltype:=UIA_EditControlTypeId;class:=") ; Reported By Phone _UIA_setVar("oPhone","Title:=Reported By Phone:;controltype:=UIA_EditControlTypeId;class:=") Local $WorkType = "CM" ; Send the stored data to the proper field Local $stringSplitter = ", " Local $conCateStrings = $eDescription & $stringSplitter & $eComments Local $ComStringLen = StringLen($eComments) Local $TrimedDesc = StringTrimLeft($eDescription, 1) ;=============================================================================== ; Check to see if the Description and the Long Description can be concatenated If StringLen($conCateStrings) <= 100 Then Sleep(2000) _UIA_action("oDescription","highlight") Sleep(300) _UIA_Action("oDescription","setfocus") Sleep(300) _UIA_action("oDescription","click") Sleep(500) _UIA_action("oDescription", "setvalue", $conCateStrings) _UIA_action("oDescription","highlight") ; Wipes the long description so no duplication happens $eComments = "" ;=============================================================================== ; Send the Long Description in place of the Description ElseIf $TrimedDesc = "Other" AND $ComStringLen <= 100 Then Sleep(2000) _UIA_action("oDescription","highlight") Sleep(300) _UIA_Action("oDescription","setfocus") Sleep(300) _UIA_action("oDescription","click") Sleep(500) _UIA_action("oDescription", "setvalue", $eComments) _UIA_action("oDescription","highlight") Sleep(2000) ;=============================================================================== ; Send the Long Description in place of the Description and Send the rest of it to the Long Description field ElseIf $TrimedDesc = "Other" AND $ComStringLen >= 100 Then SplitLongDesc() ; Description gets the first 100 Characters $eDescription = $FirstLine ; Long Description gets the rest $eComments = StringMid($sNewString, 101) Sleep(2000) _UIA_action("oDescription","highlight") Sleep(500) _UIA_Action("oDescription","setfocus") Sleep(500) _UIA_action("oDescription","click") Sleep(500) _UIA_action("oDescription", "setvalue", $eDescription) _UIA_action("oDescription","highlight") Sleep(2000) ;=============================================================================== ; Send the Description and some of the Long Description ElseIf StringLen($eDescription) <= 80 AND $eComments <> "" Then SplitLongDesc() ; Description gets the first 100 Characters $eDescription = $FirstLine ; Long Description gets the rest $eComments = StringMid($sNewString, 101) Sleep(2000) _UIA_action("oDescription","highlight") Sleep(300) _UIA_Action("oDescription","setfocus") Sleep(300) _UIA_action("oDescription","click") Sleep(500) _UIA_action("oDescription", "setvalue", $eDescription) _UIA_action("oDescription","highlight") Sleep(2000) ;=============================================================================== ; Send the original Description Else Sleep(2000) _UIA_action("oDescription","highlight") Sleep(300) _UIA_Action("oDescription","setfocus") Sleep(300) _UIA_action("oDescription","click") Sleep(500) _UIA_action("oDescription", "setvalue", $eDescription) _UIA_action("oDescription","highlight") Sleep(2000) EndIf ;=============================================================================== ; Click the long description button Sleep(2000) _UIA_action("oLongButton","highlight") Sleep(300) _UIA_Action("oLongButton","setfocus") Sleep(300) _UIA_action("oLongButton", "click") _UIA_action("oLongButton", "highlight") _UIA_action("oLongButton", "click") Sleep(2000) ;=============================================================================== ; Send the long description Sleep(1000) if StringLen($eComments) >= 250 Then Sleep(500) Send($eComments) Sleep(10000) ElseIf StringLen($eComments) >= 150 Then Sleep(500) Send($eComments) Sleep(6000) ElseIf StringLen($eComments) <= 10 Then Sleep(500) Send($eComments) Sleep(1500) Else Sleep(500) Send($eComments) Sleep(4000) EndIf ;=============================================================================== ; Click the ok button Sleep(2000) _UIA_action("oLongOk","highlight") Sleep(300) _UIA_Action("oLongOk","setfocus") Sleep(300) _UIA_action("oLongOk", "click") _UIA_action("oLongOk", "highlight") Sleep(2000) ;=============================================================================== ; The work order number _UIA_action("oWorkOrderNum","highlight") Sleep(300) _UIA_Action("oWorkOrderNum","setfocus") Sleep(300) _UIA_action("oWorkOrderNum", "getvalue", $WoNum) _UIA_action("oWorkOrderNum","highlight") ;MsgBox("", "Work order number", $WoNum[2]) ;=============================================================================== ; The Location field Sleep(2000) _UIA_action("oLocation","highlight") Sleep(300) _UIA_Action("oLocation","setfocus") Sleep(300) _UIA_action("oLocation", "setvalue", $eLocation) _UIA_action("oLocation","highlight") ;=============================================================================== ; The Work Type field Sleep(2000) _UIA_action("oWorkType","highlight") Sleep(300) _UIA_Action("oWorkType","setfocus") Sleep(300) _UIA_action("oWorkType", "setvalue", $WorkType) _UIA_action("oWorkType","highlight") ;=============================================================================== ; The Reported By Date Sleep(2000) _UIA_action("oDate","highlight") Sleep(300) _UIA_Action("oDate","setfocus") Sleep(300) _UIA_action("oDate", "setvalue", $eSentOn) _UIA_action("oDate","highlight") ;=============================================================================== ; The Requested by field Sleep(2000) _UIA_action("oCustomer","highlight") Sleep(300) _UIA_Action("oCustomer","setfocus") Sleep(300) _UIA_action("oCustomer", "setvalue", $eReportedBy) _UIA_action("oCustomer","highlight") ;=============================================================================== ; The Requested by E-mail Sleep(2000) _UIA_action("oEmail","highlight") Sleep(300) _UIA_Action("oEmail","setfocus") Sleep(300) _UIA_action("oEmail", "setvalue", $eSenderAddress) _UIA_action("oEmail","highlight") ;=============================================================================== ; The Requested by Phone Sleep(2000) _UIA_action("oPhone","highlight") Sleep(300) _UIA_Action("oPhone","setfocus") Sleep(300) _UIA_action("oPhone", "setvalue", $eRoomPhone) _UIA_action("oPhone","highlight") MouseClick("left", 1843, 437, 2) Sleep(1500) Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Sleep(1000) MouseClick("left", 591, 279, 2) Sleep(3000) $lCount += 1 ConsoleWrite("Action 16: Finished" & " at line: " & @ScriptLineNumber & @CRLF) Sleep(2000) EndFunc  
      That is not all the code but that is the function that keeps "breaking" and by "breaking" I mean the program acts like it doesn't know where the description field is after the first iteration.
      My code will just click somewhere in the far top left corner and somehow shrink the browser in the process of finding the description field.  
       
      The code works perfectly the first iteration but after that, it "breaks" (doesn't know where to click/send data to). 
      As always any help is greatly appreciated. 
       
      NOTE: By the time 'Action 16' runs Chrome has already been opened and has navigated to the proper webpage.  I am trying to loop 'Action 16' multiple times. I do not leave that webpage while looping. 
×
×
  • Create New...