gtrotter Posted July 26, 2020 Share Posted July 26, 2020 I'm trying to set a date to the DateTimePicker control below. I've used the below code; and I can see the date is being updated in the UI: <Dim $fDate[7] = [False, 2020, 06, 01, 0, 0, 0]> <$hDTP1=ControlGetHandle("NET TICKETING Version(2) Date :- 24-5-2016","","[NAME:dtp1]")> <_GUICtrlDTP_SetSystemTime($hDTP1, $fDate)> However, I can confirm the date selection hasn't reflected in the workflow. In a following button control, which uploads a file based on above date; I'm unable to upload the file due to wrong date selection. When I try to manually select the date; the uploading part works just fine. I'm a newbie in AutoIt and any insight is appreciated. Link to comment Share on other sites More sharing options...
Nine Posted July 26, 2020 Share Posted July 26, 2020 Have you set any error handling ? You should do so in order to know where an error has occurred. If you cannot find a solution, please provide a runable snippet of your code using this tool. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
gtrotter Posted July 26, 2020 Author Share Posted July 26, 2020 expandcollapse popup#include <GuiDateTimePicker.au3> #include <Date.au3> ;Call the function to initiate the script CallScript() Func CallScript() ;Assign the exe path to a variable, reading from the .ini file Local const $scriptPath = IniRead(@ScriptDir&"\scriptData.ini","Section1","scriptPath",0) Local const $freedomFile = IniRead(@ScriptDir&"\scriptData.ini","Section2","freedomFile",0) ;Run the application Run($scriptPath) ;Calculate the last month Local $sLastMonth = @MON-1 ;Declare lastyear and days variables Local $lastYear Local $iDays ;Check if last month is 0, which means, is a year change and the month corresponds to December if $sLastMonth = 0 Then ;If yes, assign 12 to month meaning month being December $sLastMonth = 12 ;Decrement the year by 1 $lastYear = @YEAR - 1 ;Find the number of days in the month $iDays = _DateDaysInMonth( @YEAR, 12) Else $lastYear = @YEAR $iDays = _DateDaysInMonth( @YEAR, $sLastMonth) EndIf ;Wait 10 seconds for the Notepad window to appear. Local $hWnd = WinWait("[CLASS:WindowsForms10.Window.8.app.0.33c0d9d]", "") ;Create Date array to store the previous month date values Dim $fDate[7] = [False, $lastYear, $sLastMonth, 01, 0, 0, 0] Dim $tDate[7] = [False, $lastYear, $sLastMonth, $iDays, 0, 0, 0] ;Assign the date values to DTP controls in script UI for From and To Date controls $hDTP1=ControlGetHandle("NET TICKETING Version(2) Date :- 24-5-2016","","[NAME:dtp1]") _GUICtrlDTP_SetSystemTime($hDTP1, $fDate) $hDTP2=ControlGetHandle("NET TICKETING Version(2) Date :- 24-5-2016","","[NAME:dtp2]") _GUICtrlDTP_SetSystemTime($hDTP2, $tDate) Sleep(1000) ;Send a mouse click to the TIDC File button ControlClick($hWnd, "", "WindowsForms10.BUTTON.app.0.33c0d9d5") Sleep(1000) ;Send a mouse click to the OK Button in the popup ControlClick("Note", "", "Button1") Sleep(1500) ;Send filepath to the active control area Send($freedomFile) Sleep(1000) ;Send a mouse click to the TIDC File button ControlClick("Open", "", "Button1") Sleep(1500) ;Click in Unique NNTC Button ControlClick($hWnd, "", "WindowsForms10.BUTTON.app.0.33c0d9d1") Sleep(2000) if WinActive("Note") = True Then ControlClick("Note", "", "Button1") Sleep(1500) EndIf ; Close WinClose($hWnd) EndFunc ;==>Example Link to comment Share on other sites More sharing options...
gtrotter Posted July 26, 2020 Author Share Posted July 26, 2020 I'm trying to automate a windows forms application that's been developed by a 3rd party. Link to comment Share on other sites More sharing options...
Nine Posted July 26, 2020 Share Posted July 26, 2020 I see. That is not a runable script. I cannot run this since I do not have the application. Like I previously said, you should definitely add error handling to your code. Here an example of what you should do : $hDTP1=ControlGetHandle("NET TICKETING Version(2) Date :- 24-5-2016","","[NAME:dtp1]") ConsoleWrite ("$hDTP1 = " & $hDTP1 & "/" & @error & @CRLF) Do the same thing everywhere there is a possibility of an error. Report back Scite console. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
gtrotter Posted July 26, 2020 Author Share Posted July 26, 2020 Honestly, I don't think there is an error in the code. (I'm not sure if I overlook). I can see the DTPicker getting updated with the date I set in UI correctly; however it's not updated properly (I assume) so the rest actions that depend on date selection is unable to complete. I have run the snippet you shared and here is the output: Link to comment Share on other sites More sharing options...
Nine Posted July 26, 2020 Share Posted July 26, 2020 3 minutes ago, gtrotter said: I don't think there is an error in the code Well if there is no error then it should work, right ? But it does not. So I repeat for the last time, add error handling a every single line of code including _GUICtrl* function. I cannot debug this code for you, you will need to make an effort. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
gtrotter Posted July 26, 2020 Author Share Posted July 26, 2020 I have tried adding the error handling and below is what i could find in the console: Link to comment Share on other sites More sharing options...
Nine Posted July 26, 2020 Share Posted July 26, 2020 Change also : $iRet = _GUICtrlDTP_SetSystemTime($hDTP1, $fDate) ConsoleWrite ("GUIctrl hDTP1 = " & $iRet & @CRLF) Post your script when done with the console result. Image is not good. Thanks. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
gtrotter Posted July 26, 2020 Author Share Posted July 26, 2020 Sure. expandcollapse popup#include <GuiDateTimePicker.au3> #include <Date.au3> ;Call the function to initiate the script CallScript() Func CallScript() ;Assign the exe path to a variable, reading from the .ini file Local const $scriptPath = IniRead(@ScriptDir&"\scriptData.ini","Section1","scriptPath",0) ConsoleWrite ("$scriptPath = " & $scriptPath & "/" & @error & @CRLF) Local const $freedomFile = IniRead(@ScriptDir&"\scriptData.ini","Section2","freedomFile",0) ConsoleWrite ("$freedomFile = " & $freedomFile & "/" & @error & @CRLF) ;Run the application Run($scriptPath) ;Calculate the last month Local $sLastMonth = @MON-1 ConsoleWrite ("$sLastMonth = " & $sLastMonth & "/" & @error & @CRLF) ;Declare lastyear and days variables Local $lastYear Local $iDays ;Check if last month is 0, which means, is a year change and the month corresponds to December if $sLastMonth = 0 Then ;If yes, assign 12 to month meaning month being December $sLastMonth = 12 ConsoleWrite ("$sLastMonth = " & $sLastMonth & "/" & @error & @CRLF) ;Decrement the year by 1 $lastYear = @YEAR - 1 ConsoleWrite ("$lastYear = " & $lastYear & "/" & @error & @CRLF) ;Find the number of days in the month $iDays = _DateDaysInMonth( @YEAR, 12) Else $lastYear = @YEAR ConsoleWrite ("$lastYear = " & $lastYear & "/" & @error & @CRLF) $iDays = _DateDaysInMonth( @YEAR, $sLastMonth) ConsoleWrite ("$iDays = " & $iDays & "/" & @error & @CRLF) EndIf ;Wait 10 seconds for the Notepad window to appear. Local $hWnd = WinWait("[CLASS:WindowsForms10.Window.8.app.0.33c0d9d]", "") ConsoleWrite ("$hWnd = " & $hWnd & "/" & @error & @CRLF) ;Create Date array to store the previous month date values Dim $fDate[7] = [False, $lastYear, $sLastMonth, 01, 0, 0, 0] Dim $tDate[7] = [False, $lastYear, $sLastMonth, $iDays, 0, 0, 0] For $i = 0 to 6 ConsoleWrite ("$fDate = " & $fDate[$i] & "/" & @error & @CRLF) ConsoleWrite ("$tDate = " & $tDate[$i] & "/" & @error & @CRLF) Next ;Assign the date values to DTP controls in script UI for From and To Date controls $hDTP1=ControlGetHandle("NET TICKETING Version(2) Date :- 24-5-2016","","[NAME:dtp1]") ConsoleWrite ("$hDTP1 = " & $hDTP1 & "/" & @error & @CRLF) $iRet1 = _GUICtrlDTP_SetSystemTime($hDTP1, $fDate) ConsoleWrite ("GUIctrl hDTP1 = " & $iRet1 & @CRLF) $hDTP2=ControlGetHandle("NET TICKETING Version(2) Date :- 24-5-2016","","[NAME:dtp2]") ConsoleWrite ("$hDTP2 = " & $hDTP2 & "/" & @error & @CRLF) $iRet2 = _GUICtrlDTP_SetSystemTime($hDTP2, $tDate) ConsoleWrite ("GUIctrl hDTP2 = " & $iRet2 & @CRLF) Sleep(1000) ;Send a mouse click to the TIDC File button ControlClick($hWnd, "", "WindowsForms10.BUTTON.app.0.33c0d9d5") ConsoleWrite ("$hWnd = " & $hWnd & "/" & @error & @CRLF) Sleep(1000) ;Send a mouse click to the OK Button in the popup ControlClick("Note", "", "Button1") ConsoleWrite ("$hWnd = " & $hWnd & "/" & @error & @CRLF) Sleep(1500) ;Send filepath to the active control area Send($freedomFile) Sleep(1000) ;Send a mouse click to the TIDC File button ControlClick("Open", "", "Button1") Sleep(1500) ;Click in Unique NNTC Button ControlClick($hWnd, "", "WindowsForms10.BUTTON.app.0.33c0d9d1") Sleep(2000) if WinActive("Note") = True Then ConsoleWrite ("is window active = " & WinActive("Note") & "/" & @error & @CRLF) ControlClick("Note", "", "Button1") Sleep(1500) EndIf ; Close the Notepad window using the handle returned by WinWait. WinClose($hWnd) EndFunc ; >"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Amadeus Projects\FreedomAutomation\freedomAutoIt.au3" $scriptPath = C:\Amadeus Projects\FreedomAutomation\NNTC\NetTicketing.exe/0 $freedomFile = C:\Amadeus Projects\FreedomAutomation\PRD.NBC.TJDVPA01.SNAE.RAW.M202006/0 $sLastMonth = 6/0 $lastYear = 2020/0 $iDays = 30/0 $hWnd = 0x0036085E/0 $fDate = False/0 $tDate = False/0 $fDate = 2020/0 $tDate = 2020/0 $fDate = 6/0 $tDate = 6/0 $fDate = 1/0 $tDate = 30/0 $fDate = 0/0 $tDate = 0/0 $fDate = 0/0 $tDate = 0/0 $fDate = 0/0 $tDate = 0/0 $hDTP1 = 0x0037073A/0 GUIctrl hDTP1 = True $hDTP2 = 0x00360772/0 GUIctrl hDTP2 = True $hWnd = 0x0036085E/0 $hWnd = 0x0036085E/0 is window active = 0x005A0D76/0 >Exit code: 0 Time: 11.34 Console added above. Link to comment Share on other sites More sharing options...
Nine Posted July 26, 2020 Share Posted July 26, 2020 Alright everything seems to go well up to the first ControlClick. So if I understand you right, the dates are set and displayed correctly, but the information doesn't seem to be registered within the application, is that it ? Could you modify your script with this : ;Assign the date values to DTP controls in script UI for From and To Date controls $hDTP1=ControlGetHandle("NET TICKETING Version(2) Date :- 24-5-2016","","[NAME:dtp1]") ConsoleWrite ("$hDTP1 = " & $hDTP1 & "/" & @error & @CRLF) $iRet1 = _GUICtrlDTP_SetSystemTime($hDTP1, $fDate) ConsoleWrite ("GUIctrl hDTP1 = " & $iRet1 & @CRLF) $hDTP2=ControlGetHandle("NET TICKETING Version(2) Date :- 24-5-2016","","[NAME:dtp2]") ConsoleWrite ("$hDTP2 = " & $hDTP2 & "/" & @error & @CRLF) $iRet2 = _GUICtrlDTP_SetSystemTime($hDTP2, $tDate) ConsoleWrite ("GUIctrl hDTP2 = " & $iRet2 & @CRLF) Local $aArray = _GUICtrlDTP_GetSystemTime($hDTP1) _ArrayDisplay ($aArray, "dtp1") $aArray = _GUICtrlDTP_GetSystemTime($hDTP2) _ArrayDisplay ($aArray, "dtp2") Sleep(1000) ;Send a mouse click to the TIDC File button $iret = ControlClick($hWnd, "", "WindowsForms10.BUTTON.app.0.33c0d9d5") ConsoleWrite ("click = " & $iret & "/" & @error & @CRLF) Verify if the Gets return the right values. gtrotter 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
TheXman Posted July 26, 2020 Share Posted July 26, 2020 (edited) I think that the issue here may be that although _GUICtrlDTP_SetSystemTime() is setting the DTP control's fields, it is not forcing the underlying DATETIMECHANGE event to fire, which ultimately updates to control's values. To force the event to fire, the control's UI needs to recognize a change. Below is a quick & easy way to verify if this is the case and to workaround the issue. Can you try adding the the following lines after your _GUICtrlDTP_SetSystemTime() functions so that they look like this: $iRet1 = _GUICtrlDTP_SetSystemTime($hDTP1, $fDate) ControlFocus($hwnd, "", $hDTP1) ControlSend($hwnd, "", $hDTP1, "!{DOWN}") ;open calendar ControlSend($hwnd, "", $hDTP1, "{ENTER}") ;confirm selection AND $iRet2 = _GUICtrlDTP_SetSystemTime($hDTP2, $tDate) ControlFocus($hwnd, "", $hDTP2) ControlSend($hwnd, "", $hDTP2, "!{DOWN}") ;open calendar ControlSend($hwnd, "", $hDTP2, "{ENTER}") ;confirm selection This works for me when testing against standard Win32 DTP controls. Edited July 26, 2020 by TheXman Corrected typo gtrotter 1 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Nine Posted July 26, 2020 Share Posted July 26, 2020 I agree with you @TheXman, this is where I was going, just wanna make sure the info was correctly set. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
gtrotter Posted July 26, 2020 Author Share Posted July 26, 2020 @TheXman I have tried the piece of code you suggested. However it seemed not doing any difference. Link to comment Share on other sites More sharing options...
gtrotter Posted July 26, 2020 Author Share Posted July 26, 2020 @Nine Yes, I agree the dates are set and displayed correctly, but the information doesn't seem to be registered within the application. And implementing your code, I get the desired/right values from Gets. Link to comment Share on other sites More sharing options...
Nine Posted July 26, 2020 Share Posted July 26, 2020 Ok tested for WM_NOTIFY - DATETIMECHANGE event and it seems it doesn't get notify if you do not change the date. So try this : $iRet1 = _GUICtrlDTP_SetSystemTime($hDTP1, $fDate) ControlFocus($hwnd, "", $hDTP1) ControlSend($hwnd, "", $hDTP1, "!{DOWN}") ;open calendar ControlSend($hwnd, "", $hDTP1, "{UP}{DOWN}{ENTER}") ;confirm selection AND $iRet2 = _GUICtrlDTP_SetSystemTime($hDTP2, $tDate) ControlFocus($hwnd, "", $hDTP2) ControlSend($hwnd, "", $hDTP2, "!{DOWN}") ;open calendar ControlSend($hwnd, "", $hDTP2, "{UP}{DOWN}{ENTER}") ;confirm selection gtrotter 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
gtrotter Posted July 26, 2020 Author Share Posted July 26, 2020 Wow @Nine!! Worked super cool! You're a lifesaver, thank you! This does the magic! $iRet1 = _GUICtrlDTP_SetSystemTime($hDTP1, $fDate) ControlFocus($hwnd, "", $hDTP1) ControlSend($hwnd, "", $hDTP1, "!{DOWN}") ;open calendar ControlSend($hwnd, "", $hDTP1, "{UP}{DOWN}{ENTER}") ;confirm selection Link to comment Share on other sites More sharing options...
Nine Posted July 26, 2020 Share Posted July 26, 2020 Glad we found a solution for you gtrotter 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy 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