Brasco Posted July 21, 2017 Share Posted July 21, 2017 Any ideas on how I would go about pulling the first day of the last month and the last day of the last month into a form? In a nutshell, I want to automate a monthly report that on the first day of the month, runs the report for the previous month without having to manually update the script each time. Curious if there is a way to do this? I haven't been able to find anything online. Thanks in advance. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted July 21, 2017 Moderators Share Posted July 21, 2017 (edited) @Brasco are you looking for just the date? Or the date and day? This is a simple one for the last day date, day is a bit more. You could easily modify for first day of month: #include <Date.au3> Local $sLastMonth = (@MON - 1) Local $iDays = _DateDaysInMonth( @YEAR, $sLastMonth) ConsoleWrite($sLastMonth & "/" & $iDays & "/" & @YEAR & @CRLF) Edit: Admittedly, you'll need another statement to handle it if you're in January and looking to go back to the previous month and year, but this should at least get you started. Ask if you have any questions. Edited July 21, 2017 by JLogan3o13 "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...
Malkey Posted July 21, 2017 Share Posted July 21, 2017 The "controlID" parameters of the ControlSend() functions may be incorrect in this example and need changing. #include <Date.au3> #include <Array.au3> ; For display purposes only. ;$aArray = _Date_GetFirst_LastOfPreviousMonth("2017/01/02") ; Test a January date as a parameter for the _Date_GetFirst_LastOfPreviousMonth() function. ; Or $aArray = _Date_GetFirst_LastOfPreviousMonth(_NowCalcDate()) ; Use _NowCalcDate() as parameter for the current date. _ArrayDisplay($aArray) ; Note: ClassnameNN property for the "controlID" parameter of the ControlSend() function can be found by using AutoIt's ; "AU3Info" tool. This tool is found in "SciTE > Tools" menu, or, "Au3info.exe" from ...\(Install directory of )AutoIt3\Au3info.exe If WinExists("Select Report Criteria") Then WinActivate("Select Report Criteria") WinWaitActive("Select Report Criteria") ControlSend("Select Report Criteria", "", "Edit1", $aArray[0]) ; Assuming top input box has a ClassnameNN property of "Edit1" ControlSend("Select Report Criteria", "", "Edit2", $aArray[1]) ; Assuming the next input box has a ClassnameNN property of "Edit2" Else MsgBox(0, "Error", 'Window with title "Select Report Criteria" does not exist.') EndIf ; Function ------------ _Date_GetFirst_LastOfPreviousMonth ----------------- ; Only parameter - Date in the format is "YYYY/MM/DD" ; Returns an Array - First element - Array[0] - Start date of previous month in the format of "MM/DD/YYYY". ; - Second element - Array[1] - Last date of previous month in the format of "MM/DD/YYYY". Func _Date_GetFirst_LastOfPreviousMonth($iThisMonth) Local $sLastMonth = _DateAdd("M", -1, $iThisMonth) Local $iDays = _DateDaysInMonth(StringLeft($sLastMonth, 4), StringMid($sLastMonth, 6, 2)) Local $aRetArray = [StringMid($sLastMonth, 6, 2) & "/01/" & StringLeft($sLastMonth, 4), _ StringMid($sLastMonth, 6, 2) & "/" & $iDays & "/" & StringLeft($sLastMonth, 4)] Return $aRetArray EndFunc ;==>_Date_GetFirst_LastOfPreviousMonth Link to comment Share on other sites More sharing options...
Gianni Posted July 21, 2017 Share Posted July 21, 2017 hi @Malkey, I've simplified your function a bit ; Function ------------ _Date_GetFirst_LastOfPreviousMonth ----------------- ; Only parameter - Date in the format is "YYYY/MM/DD" ; Returns an Array - First element - Array[0] - Start date of previous month in the format of "MM/DD/YYYY". ; - Second element - Array[1] - Last date of previous month in the format of "MM/DD/YYYY". Func _Date_GetFirst_LastOfPreviousMonth($iThisMonth) If Not _DateIsValid($iThisMonth) Then Return SetError(1, 0, "") Local $aDate = StringSplit(_DateAdd('M', -1, $iThisMonth), '/', 2) Local $sYM = $aDate[0] & '/' & $aDate[1] & '/' Local $aRetArray = [$sYM & "01", $sYM & _DateDaysInMonth($aDate[0], $aDate[1])] Return $aRetArray EndFunc ;==>_Date_GetFirst_LastOfPreviousMonth Skysnake 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Brasco Posted July 24, 2017 Author Share Posted July 24, 2017 Thanks a ton for your help. I'm going to work on this today and i'll report back my results. Link to comment Share on other sites More sharing options...
Brasco Posted July 24, 2017 Author Share Posted July 24, 2017 I can see this is doing exactly what it should be but I need a little more help (sorry, scripting is new to me). This makes it all the way to the point of displaying the array and the data is correct, but for the life of me I can't figure out how to actually transfer that data to the form. I've confirmed the controlID params as: ControlSend("Select Report Criteria", "", "[CLASS:Edit; INSTANCE:1]", $aArray[0]) ControlSend("Select Report Criteria", "", "[CLASS:Edit; INSTANCE:2]", $aArray[1]) ..but I'm not sure why it doesnt seem to be returning them to the screen. Any other hints of things to look into? Thanks, Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted July 24, 2017 Moderators Share Posted July 24, 2017 @Brasco can you please post the full code you're using now, including the controlsends? It should work, but seeing what you're doing will help us help you "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...
Brasco Posted July 25, 2017 Author Share Posted July 25, 2017 @JLogan3o13 der, I figured it out. There was a _ArrayDisplay($aArray) comment in the code that i commented out and now it's doing what it should be doing. Appreciate the followup and next time will paste the full code in - I'm sure that would have been useful the first time I asked! Thanks again, the support here has been great. 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