Brent Fanguy Posted December 29, 2015 Share Posted December 29, 2015 I have a scheduled task in windows that runs an autoit script during business hours daily. I do not want to run this section of code if it is the last business day of the month (would be great if the logic included holidays but i am ok if it does not.' something like If Now() <> LastBuisnessWorkDay Then$Run = "C:\Infor\Vmfg654\vmaplutl.exe -d " & $Database & " -u SYSADM -p yourpsw"Run($Run)WinWaitActive("Costing Utilities - Infor ERP VE")Send("!f")Sleep(1000)Send("n")WinActivate ("Costing Utilities", "OK")WinWaitActive("Costing Utilities","OK")ControlClick("Costing Utilities", "OK", "Button1") WinClose("Costing Utilities")'End If Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted December 29, 2015 Moderators Share Posted December 29, 2015 @Brent Fanguy welcome to the forum. Are you just looking for the last weekday of the month? If so there are a number of examples on the forum. Here is one that I use:#include <Date.au3> #include <MsgBoxConstants.au3> MsgBox($MB_OK, "Last WeekDay", _lastWorkDay(4, 2016)) Func _lastWorkDay($iMonth, $iYear) Local $iLastWeekDay Local $iDaysInMonth = _DateDaysInMonth($iYear, $iMonth) Local $iWeekday = _DateToDayOfWeekISO($iYear, $iMonth, $iDaysInMonth) Switch $iWeekday Case 6, 7 $iLastWeekDay = $iMonth & "/" & $iDaysInMonth - (($iWeekday = 7) ? 2 : 1) & "/" & $iYear Case Else $iLastWeekDay = $iMonth & "/" & $iDaysInMonth & "/" & $iYear EndSwitch Return $iLastWeekDay EndFunc "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
MuffinMan Posted December 30, 2015 Share Posted December 30, 2015 This thread may be helpful in setting up an array to determine if a date is a holiday: Link to comment Share on other sites More sharing options...
Brent Fanguy Posted December 30, 2015 Author Share Posted December 30, 2015 thanks, guys.what am i doing wrong?#include <Date.au3>#include <MsgBoxConstants.au3>'MsgBox($MB_OK, "Last WeekDay", _lastWorkDay(2, 2016))MsgBox($MB_OK, "Last WeekDay", _lastWorkDay(@MON, @YEAR))$date = @MON & "/" & @MDAY & "/" & @YEARMsgBox($MB_OK, "current date", $date)If $date = _lastWorkDay(@MON, @YEAR)) Then ' i get an error on this line - it does not like my If $date MsgBox($MB_OK,"=")Else MsgBox($MB_OK,"<>")EndIfFunc _lastWorkDay($iMonth, $iYear) Local $iLastWeekDay Local $iDaysInMonth = _DateDaysInMonth($iYear, $iMonth) Local $iWeekday = _DateToDayOfWeekISO($iYear, $iMonth, $iDaysInMonth) Switch $iWeekday Case 6, 7 $iLastWeekDay = $iMonth & "/" & $iDaysInMonth - (($iWeekday = 7) ? 2 : 1) & "/" & $iYear Case Else $iLastWeekDay = $iMonth & "/" & $iDaysInMonth & "/" & $iYear EndSwitch Return $iLastWeekDayEndFunc Link to comment Share on other sites More sharing options...
Danyfirex Posted December 30, 2015 Share Posted December 30, 2015 You put two )) at end.Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Brent Fanguy Posted December 30, 2015 Author Share Posted December 30, 2015 forest for the trees..... thanks Link to comment Share on other sites More sharing options...
Brent Fanguy Posted December 30, 2015 Author Share Posted December 30, 2015 Thanks guys, this is what i am using in case anyone else stumbles across this:#include <Date.au3> $date = @MON & "/" & @MDAY & "/" & @YEAR If $date <> _lastWorkDay(@MON, @YEAR) Then $Run = "C:\Infor\Vmfg654\vmaplutl.exe" Run($Run) EndIf Func _lastWorkDay($iMonth, $iYear) Local $iLastWeekDay Local $iDaysInMonth = _DateDaysInMonth($iYear, $iMonth) Local $iWeekday = _DateToDayOfWeekISO($iYear, $iMonth, $iDaysInMonth) Switch $iWeekday Case 6, 7 $iLastWeekDay = $iMonth & "/" & $iDaysInMonth - (($iWeekday = 7) ? 2 : 1) & "/" & $iYear Case Else $iLastWeekDay = $iMonth & "/" & $iDaysInMonth & "/" & $iYear EndSwitch Return $iLastWeekDay EndFunc Link to comment Share on other sites More sharing options...
MuffinMan Posted December 30, 2015 Share Posted December 30, 2015 BrentFanGuy, this topic has interested me since I read the initial thread this morning. I have put together some code that will also check for some holidays (based off the code I referenced upthread) if you're still interested. I left the original check for Easter out because it adds a lot of lines to the code. I have just been toying with this in my spare time today so there could be some errors in there, but it seems to be working fine for me. expandcollapse popup#include <Date.au3> #include <Array.au3> $date = @MON & "/" & @MDAY & "/" & @YEAR If $Date <> _lastWorkDay(@MON, @YEAR) AND _IsHoliday($Date) = False Then $Run = "C:\Infor\Vmfg654\vmaplutl.exe" Run($Run) EndIf Func _lastWorkDay($iMonth, $iYear) Local $iLastWeekDay Local $iDaysInMonth = _DateDaysInMonth($iYear, $iMonth) Local $iWeekday = _DateToDayOfWeekISO($iYear, $iMonth, $iDaysInMonth) Switch $iWeekday Case 6, 7 $iLastWeekDay = $iMonth & "/" & $iDaysInMonth - (($iWeekday = 7) ? 2 : 1) & "/" & $iYear Case Else $iLastWeekDay = $iMonth & "/" & $iDaysInMonth & "/" & $iYear EndSwitch Return $iLastWeekDay EndFunc Func _IsHoliday($Date) $IsHoliday = False Local $Year = StringRight($Date, 4) ; get the year Dim $Thanksgiving ; Thanksgiving is always the 4th Thurs of November $NumofThurs = 0 For $i = 1 to 30 Local $iWeekday = _DateToDayOfWeek($Year, 11, $i) If $iWeekday = 5 Then ; (5) = Thursday $NumofThurs = $NumofThurs + 1 EndIf If $NumofThurs = 4 Then $Thanksgiving = "11/" & $i & "/" & $Year ExitLoop EndIf Next ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Thanksgiving = ' & $Thanksgiving & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Dim $MemorialDay ; Last Monday in May For $i = 31 to 24 Step -1 Local $iWeekday = _DateToDayOfWeek($Year, 5, $i) If $iWeekday = 2 Then ; (2) = Monday $MemorialDay = "05/" & $i & "/" & $Year ExitLoop EndIf Next ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $MemorialDay = ' & $MemorialDay & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Dim $LaborDay ; 1st Monday in Sept For $i = 1 to 7 Local $iWeekday = _DateToDayOfWeek($Year, 9, $i) If $iWeekday = 2 Then ; (2) = Monday $i = StringRight("0" & $i,2) $LaborDay = "09/" & $i & "/" & $Year ExitLoop EndIf Next ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $LaborDay = ' & $LaborDay & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Local $aHDay[1] _ArrayAdd($aHDay, "01/01/" & $Year) ; New Years _ArrayAdd($aHDay, "/12/25/" & $Year) ; Christmas Day _ArrayAdd($aHDay, $Thanksgiving) ; Thanksgiving _ArrayAdd($aHDay, $MemorialDay) ; Memorial Day _ArrayAdd($aHDay, $LaborDay) ; Memorial Day _ArrayAdd($aHDay, "12/30/2015") ; Every Day should be a holiday, right? ; add other national holidays here: For $i = 1 To UBound($aHDay) - 1 If $Date = $aHDay[$i] Then $IsHoliday = True ExitLoop EndIf Next Return $IsHoliday EndFunc ;==>_IsHoliday Link to comment Share on other sites More sharing options...
junkew Posted December 31, 2015 Share Posted December 31, 2015 And how to deal worldwide with holidays ;-). Holidays differ per country and even within a country based on religion people have different free days. FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now