Jump to content

Unable to set Calendar Date using _GUICtrlDTP_SetSystemTime


Recommended Posts

I'm trying to set a date to the DateTimePicker control below.

 image.png.ef85de20e67944a824e3e3067ebf43bb.png

 

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

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.

Link to comment
Share on other sites

#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

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.

Link to comment
Share on other sites

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:

image.png.3c249bef2e3f5dd87c12327d43a64c0d.png

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Link to comment
Share on other sites

Sure.

 

#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

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.

Link to comment
Share on other sites

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 by TheXman
Corrected typo
Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...