Jump to content

Can't change time in a Date control


4Eyes
 Share

Recommended Posts

Folks,

According to the help file I should be able to change the time in a date control with GUICtrlSetData(), but using the code below the GUICtrlSetData() actually fails. I'd prefer not to use a DTP control as this is far more than what I want. Is there a solution to this?

Regards,

4Eyes

#include <DateTimeConstants.au3>

$Form1 = GUICreate("Test", 319, 290, 198, 114)
$n = GUICtrlCreateDate("", 100, 108, 100, 25, $DTS_TIMEFORMAT)
GUISetState(@SW_SHOW)
$temp = GUICtrlRead($n)
$rc = GUICtrlSetData($n, "11:30:00 AM")         ; This returns 0 and doesn't change control
MsgBox(0, "", "Tried to set time to 11:30:00 AM, $rc from GUICtrlSetData() = " & $rc)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Link to comment
Share on other sites

Well, thanks guys, but I thought there'd be a real answer to this as it seems to be a bug.

what I've come up with is to read the current system time, change it to be an hour ahead (or as far in the future as I'd like), set the control from that, then restore the original time.

4Eyes

Link to comment
Share on other sites

@4Eyes,

#include <GuiConstantsEx.au3>
#include <DateTimeConstants.au3>

$Form1 = GUICreate("Test", 319, 290, 198, 114)
$n = GUICtrlCreateDate("", 100, 108, 100, 25, $DTS_TIMEFORMAT)
GUISetState(@SW_SHOW)
$temp = GUICtrlRead($n)
GUICtrlSetState($n, $GUI_FOCUS)
$rc = ControlSend($Form1,"", GUICtrlGetHandle($n), "11:30:00:AM")
MsgBox(0, "", "Tried to set time to 11:30:00 AM, $rc from GUICtrlSetData() = " & $rc)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

:)

Edit: Changed $rc = ControlSend($Form1,"", GUICtrlGetHandle($n), "11:30:00{RIGHT}AM") to "11:30:00:AM" , easier syntax and works too.

Edited by ResNullius
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...