TheDcoder Posted July 19, 2020 Posted July 19, 2020 Hi everyone, I am bit stumped as to why I am not able to set the time in the Date control #include <DateTimeConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Example() Func Example() GUICreate("My GUI get date", 200, 200, 800, 200) Local $idDate = GUICtrlCreateDate("1953/04/25", 10, 10, 185, 20, $DTS_TIMEFORMAT) ; to select a specific default format Local $sStyle = "HH:mm:ss" GUICtrlSendMsg($idDate, $DTM_SETFORMATW, 0, $sStyle) ; Set time Local $iRet = GUICtrlSetData($idDate, '13:33:37') ConsoleWrite('GUICtrlSetData returned ' & ($iRet = 1 ? 'success' : 'failure') & @CRLF) GUISetState(@SW_SHOW) ; Loop until the user exits. While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd MsgBox($MB_SYSTEMMODAL, "Time", GUICtrlRead($idDate)) EndFunc ;==>Example The documentation for GUICtrlSetData clearly mentions that it uses the same format as GUICtrlRead: Quote For Date controls: The date and time is in the format defined by the regional settings. GUICtrlRead() use the same default format. But I get failure What gives? Thanks for the help in advance! EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
TheSaint Posted July 19, 2020 Posted July 19, 2020 (edited) I know I gave you this in HexChat, but I should add here in this topic. What one of my programs uses. $Group_from = GuiCtrlCreateGroup("Update From", 10, 10, 190, 55) $Date_from = GuiCtrlCreateDate($now, 20, 30, 90, 20) $Date_fromtime = GuiCtrlCreateDate($time, 120, 30, 70, 20, $DTS_TIMEFORMAT) $DTM_SETFORMAT_ = 0x1032 $style = "yyyy/MM/dd" GUICtrlSendMsg($Date_from, $DTM_SETFORMAT_, 0, $style) $style = "HH:mm:ss" GUICtrlSendMsg($Date_fromtime, $DTM_SETFORMAT_, 0, $style) Hope it helps. Edited July 19, 2020 by TheSaint Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)
TheDcoder Posted July 19, 2020 Author Posted July 19, 2020 @TheSaint Thanks for posting, but I am having issues with GUICtrlSetData where I attempt to set the time in the control, do you have code which sets data? EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
TheSaint Posted July 19, 2020 Posted July 19, 2020 (edited) At the risk of going overboard, here is a related function. expandcollapse popupFunc DatesGUI($combo, $now) Local $Button_apply, $Button_x3, $Date_from, $Date_fromtime, $Date_to, $Date_totime, $Group_from, $Group_to ; Local $d1, $d2, $DatesGUI, $time ; $now = StringSplit($now, " ", 1) If $now[0] = 2 Then $time = $now[2] $now = $now[1] Else $time = "" $now = "" EndIf ;MsgBox(262192, "$now $time", $now & @LF & $time, 0, $DatesGUI) ; Script generated by AutoBuilder 0.9 Prototype $DatesGUI = GuiCreate("Dates", 280, 150, $left, -1, $WS_OVERLAPPED + $WS_CAPTION + $WS_SYSMENU _ + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_MINIMIZEBOX, $WS_EX_TOPMOST, $SBSgetGUI) ; CONTROLS $Group_from = GuiCtrlCreateGroup("Date From", 10, 10, 190, 55) If $combo = $Combo_from Then $Date_from = GuiCtrlCreateDate($now, 20, 30, 90, 20) $Date_fromtime = GuiCtrlCreateDate($time, 120, 30, 70, 20, $DTS_TIMEFORMAT) Else If $period = "...select..." Then $d1 = IniRead($inifle, "Date From", "select", "") $d1 = StringSplit($d1, " ", 1) If $d1[0] = 2 Then $d2 = $d1[2] $d1 = $d1[1] Else $d1 = "2000/01/01" $d2 = "00:00:00" EndIf Else $d1 = "2000/01/01" $d2 = "00:00:00" EndIf $Date_from = GuiCtrlCreateDate($d1, 20, 30, 90, 20) $Date_fromtime = GuiCtrlCreateDate($d2, 120, 30, 70, 20, $DTS_TIMEFORMAT) EndIf $DTM_SETFORMAT_ = 0x1032 $style = "yyyy/MM/dd" GUICtrlSendMsg($Date_from, $DTM_SETFORMAT_, 0, $style) $style = "HH:mm:ss" GUICtrlSendMsg($Date_fromtime, $DTM_SETFORMAT_, 0, $style) ; $Group_to = GuiCtrlCreateGroup("Date To", 10, 75, 190, 55) If $combo = $Combo_to Then $Date_to = GuiCtrlCreateDate($now, 20, 95, 90, 20) $Date_totime = GuiCtrlCreateDate($time, 120, 95, 70, 20, $DTS_TIMEFORMAT) Else If $perend = "...select..." Then $d1 = IniRead($inifle, "Date To", "select", "") $d1 = StringSplit($d1, " ", 1) If $d1[0] = 2 Then $d2 = $d1[2] $d1 = $d1[1] Else $d1 = "2000/01/01" $d2 = "00:00:00" EndIf Else $d1 = "2000/01/01" $d2 = "00:00:00" EndIf $Date_to = GuiCtrlCreateDate($d1, 20, 95, 90, 20) $Date_totime = GuiCtrlCreateDate($d2, 120, 95, 70, 20, $DTS_TIMEFORMAT) EndIf $style = "yyyy/MM/dd" GUICtrlSendMsg($Date_to, $DTM_SETFORMAT_, 0, $style) $style = "HH:mm:ss" GUICtrlSendMsg($Date_totime, $DTM_SETFORMAT_, 0, $style) ; $Button_apply = GuiCtrlCreateButton("Apply", 210, 15, 60, 50) GUICtrlSetFont($Button_apply, 9, 600) GUICtrlSetTip($Button_apply, "Apply the currently set date & time!") ; $Button_x3 = GuiCtrlCreateButton("EXIT", 210, 80, 60, 50, $BS_ICON) GUICtrlSetTip($Button_x3, "Exit / Close / Quit the window!") ; ; SETTINGS GUICtrlSetImage($Button_x3, $explorer, $icoX, 1) ; If $combo = $Combo_from Then GUICtrlSetState($Date_to, $GUI_DISABLE) GUICtrlSetState($Date_totime, $GUI_DISABLE) ElseIf $combo = $Combo_to Then GUICtrlSetState($Date_from, $GUI_DISABLE) GUICtrlSetState($Date_fromtime, $GUI_DISABLE) GUICtrlSetData($Date_to, $now) GUICtrlSetData($Date_totime, $time) EndIf GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Or $msg = $Button_x3 ; Exit / Close / Quit the window GUIDelete($DatesGUI) ExitLoop Case $msg = $Button_apply ; Apply the currently set date & time If $combo = $Combo_from Then $date = GUICtrlRead($Date_from) & " " & GUICtrlRead($Date_fromtime) ElseIf $combo = $Combo_to Then $date = GUICtrlRead($Date_to) & " " & GUICtrlRead($Date_totime) EndIf MsgBox(262192, "Date Check", $date, 0, $DatesGUI) GUIDelete($DatesGUI) ExitLoop Case Else ;;; EndSelect WEnd EndFunc ;=> DatesGUI I will let you nut it out with my code. I am suffering from brain drain and tiredness right now. Edited July 19, 2020 by TheSaint Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)
TheDcoder Posted July 19, 2020 Author Posted July 19, 2020 @TheSaint Can you give more info on the $now parameter in your function? It looks like an array which contains the time that you set: $time = $now[2] ; ... GUICtrlSetData($Date_totime, $time) Â EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
TheSaint Posted July 19, 2020 Posted July 19, 2020 Well the clue is in the first line of the following. $now = StringSplit($now, " ", 1) If $now[0] = 2 Then $time = $now[2] $now = $now[1] Else $time = "" $now = "" EndIf That space is the divider between DATE and TIME, probably as returned by the _Now() function. So have a try with $now = _Now() before that line ... or replace $now with _Now() $now = StringSplit(_Now(), " ", 1) Don't ask me why I am using $now instead of $date, but I imagine $date is in use as a variable elsewhere in my script. TheDcoder 1 Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)
TheDcoder Posted July 19, 2020 Author Posted July 19, 2020 @TheSaint Thanks, that clears about what $now is, but unfortunately the string returned by _Now is locale-specific, meaning it changes across different regions Quote Returns Current Date and Time in PC's format. But I want to set the time in my format, not the PC's format... EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
TheSaint Posted July 19, 2020 Posted July 19, 2020 Well isn't it as simple as converting? If the Date control requires the date or time to be in a specific format, then you are limited to that. That means you have to sanitize what you send by CtrlSetData  Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)
TheDcoder Posted July 19, 2020 Author Posted July 19, 2020 (edited) 12 minutes ago, TheSaint said: Well isn't it as simple as converting? It is as simple as converting, but conversion is the hard part, and there is no standard reference that can be used, nor is there any Windows API that I can use to convert time and date between different locales... so practically impossible unless I limit myself to a specific version of Windows in specific regional settings. -- I did find a promising alternative function (_GUICtrlDTP_SetSystemTime) that I could use to set the time, but that too didn't work: #include <DateTimeConstants.au3> #include <GUIConstantsEx.au3> #include <GuiDateTimePicker.au3> #include <MsgBoxConstants.au3> Example() Func Example() GUICreate("My GUI get date", 200, 200, 800, 200) Local $idDate = GUICtrlCreateDate("1953/04/25", 10, 10, 185, 20, $DTS_TIMEFORMAT) ; to select a specific default format Local $sStyle = "HH:mm:ss" GUICtrlSendMsg($idDate, $DTM_SETFORMATW, 0, $sStyle) ; Set time Local $aDate[7] = [True, 0, 0, 0, 13, 33, 37] Local $hDate = GUICtrlGetHandle($idDate) Local $bRet = _GUICtrlDTP_SetSystemTime($hDate, $aDate) ConsoleWrite('_GUICtrlDTP_SetSystemTime returned ' & ($bRet ? 'success' : 'failure') & @CRLF) GUISetState(@SW_SHOW) ; Loop until the user exits. While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd MsgBox($MB_SYSTEMMODAL, "Time", GUICtrlRead($idDate)) EndFunc ;==>Example  Edited July 19, 2020 by TheDcoder EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
Danp2 Posted July 19, 2020 Posted July 19, 2020 Seems like the date is required This worked for me -- Local $iRet = GUICtrlSetData($idDate, '2020/01/01 13:33:37') Â Latest Webdriver UDF Release Webdriver Wiki FAQs
TheSaint Posted July 20, 2020 Posted July 20, 2020 Yep, you can set the full date, time or just date. But that is not his issue. His issue is to do with locales ... though it seems to me he is making it more complex than it needs to be. Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)
Danp2 Posted July 20, 2020 Posted July 20, 2020 Hmmm... are you sure? His code runs correctly for me by making that one change. I can't find an example where GUICtrlSetData works when supplying time only. Latest Webdriver UDF Release Webdriver Wiki FAQs
TheDcoder Posted July 20, 2020 Author Posted July 20, 2020 @Danp2 You are right about having to include date along with the time, but like TheSaint has said, the format of date + time depends on the locale of the machine and I need my script to work in various locales, not only English-like ones. At this point I am pretty sure GUICtrlSetData only takes the region-specific string as valid input, but what stumps me is why _GUICtrlDTP_SetSystemTime also doesn't seem to work? @TheSaint Thanks for clarifying on my behalf. 2 hours ago, TheSaint said: ... though it seems to me he is making it more complex than it needs to be. Depends on how you see it, if I compromise with not properly supporting all locales, I can definitely just hardcode the English string an use a fake date to set the time. But I'd rather not do that. EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
TheDcoder Posted July 20, 2020 Author Posted July 20, 2020 (edited) 1 hour ago, TheDcoder said: but what stumps me is why _GUICtrlDTP_SetSystemTime also doesn't seem to work? Like I expected, I overlooked something simple, I had the date in the wrong order in my example, I was using DMY instead of YMD. #include <DateTimeConstants.au3> #include <GUIConstantsEx.au3> #include <GuiDateTimePicker.au3> #include <MsgBoxConstants.au3> Example() Func Example() GUICreate("My GUI get date", 200, 200, 800, 200) Local $idDate = GUICtrlCreateDate("", 10, 10, 185, 20, $DTS_TIMEFORMAT) Local $hDate = GUICtrlGetHandle($idDate) ; to select a specific default format Local $sStyle = "HH:mm:ss" GUICtrlSendMsg($idDate, $DTM_SETFORMATW, 0, $sStyle) ; Set time Local $aDate[7] = [False, 2020, 1, 1, 13, 33, 37] Local $bRet = _GUICtrlDTP_SetSystemTime($hDate, $aDate) ConsoleWrite('_GUICtrlDTP_SetSystemTime returned ' & ($bRet ? 'success' : 'failure') & @CRLF) GUISetState(@SW_SHOW) ; Loop until the user exits. While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd MsgBox($MB_SYSTEMMODAL, "Time", GUICtrlRead($idDate)) EndFunc ;==>Example This works perfectly and it doesn't even depend on strings, let alone have regional issues! I am happy Edit: Just noticed another helpful tidbit, remember to set the first element of the time/date array to False, otherwise it won't work! At-least it did not for me. Edited July 20, 2020 by TheDcoder TheSaint 1 EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
TheSaint Posted July 20, 2020 Posted July 20, 2020 1 hour ago, Danp2 said: Hmmm... are you sure? His code runs correctly for me by making that one change. I can't find an example where GUICtrlSetData works when supplying time only. I didn't run his code, and I was very tired last night, and probably shouldn't have bothered replying, but he asked me in HexChat and I remembered I had some code from years ago that probably did close to what he wanted ... it was very specific though and didn't need to cater for regions. In my code in the 4th post (my second reply) you can see I use the following. GUICtrlSetData($Date_to, $now) GUICtrlSetData($Date_totime, $time) And you can see from earlier in the code, where I set the controls up. $style = "yyyy/MM/dd" GUICtrlSendMsg($Date_to, $DTM_SETFORMAT_, 0, $style) $style = "HH:mm:ss" GUICtrlSendMsg($Date_totime, $DTM_SETFORMAT_, 0, $style) Be aware though, that I did this a few years ago with an older version of AutoIt. Â TheDcoder 1 Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)
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