Jump to content
Sign in to follow this  
SupaNewb

GUICtrlCreateDate issue

Recommended Posts

SupaNewb

Hi, Hoping someone has the time to set me straight on what I must be doing wrong.

I have a listview that (one of it's sub items) stores the date in the format "mm/dd/yyyy", Then there is a GUICtrlCreateDate control that gets updated from the corresponding listview subitem. Everything works fine except the day "dd" portion of the control never changes from the current day (as in today literally). I read the forums as well as the help guide and the only answer I have found was suggesting to set the date when the control is created. This listview holds hundreds of items that will be randomly edited so I am hoping there is a better solution. I am attaching some basic code to reproduce the issue. If it matters, I am using Win 7 O.S.

Thank you in advance.

#include <GUIConstantsEx.au3>
#include <DateTimeConstants.au3>
GUICreate("date", 200, 200, 800, 200)
$date = GUICtrlCreateDate("", 10, 40, 100, 20, $DTS_SHORTDATEFORMAT)
$dat2read = GUICtrlCreateInput("2/14/2010", 10, 10, 100, 21);date is in format of mm/dd/yyyy
$bUpdate = GUICtrlCreateButton("Update", 140, 10)
GUISetState()
While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $bUpdate
            __ChangeDate()
    EndSwitch
WEnd
Func __ChangeDate()
    Local $crInput, $sDate
    $crInput = GUICtrlRead($dat2read)
    $sDate = StringRegExpReplace($crInput, "(\d+)/(\d+)/(\d+)", "$3/$1/$2")
    GUICtrlSetData($date,$sDate)
EndFunc   ;==>__ChangeDate

Share this post


Link to post
Share on other sites
sleepydvdr

It has something to do with single digit numbers. If you change the "2/14/2010" to "02/14/2010", it works. However, using StringFormat, I can make the 2 into a 02, but then it's a string, not a number and is not accepted by GUICtrlCreateDate. I'm sorry I cannot help you any further. Perhaps one of the MVPs can help. I'm sure they are smart enough to figure it out.


#include <ByteMe.au3>

Share this post


Link to post
Share on other sites
sleepydvdr

I just couldn't give up. This works:

#include <GUIConstantsEx.au3>
#include <DateTimeConstants.au3>
#include <string.au3>
#include <array.au3>

GUICreate("date", 200, 200, 800, 200)
$date = GUICtrlCreateDate("", 10, 40, 100, 20, $DTS_SHORTDATEFORMAT)
$dat2read = GUICtrlCreateInput("2/15/2010", 10, 10, 100, 21);date is in format of mm/dd/yyyy
$bUpdate = GUICtrlCreateButton("Update", 140, 10)
GUISetState()
While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $bUpdate
            __ChangeDate()
    EndSwitch
WEnd
Func __ChangeDate()
    $crInput = GUICtrlRead($dat2read)
    $myread = GUICtrlRead($date)
    $mydate = StringSplit($crInput, "/")
    $year = StringFormat("%#.4i", $mydate[3])
    $month = StringFormat("%#.2i", $mydate[1])
    $day = StringFormat("%#.2i", $mydate[2])
    $sDate = $year & "/" & $month & "/" & $day
    GUICtrlSetData($date, $sDate)
EndFunc   ;==>__ChangeDate

#include <ByteMe.au3>

Share this post


Link to post
Share on other sites
SupaNewb

Thank you very much Sleepydvdr. Your solution works perfect incorporated into my listview. I had been wrestling with this problem for 2 days,lol.

Share this post


Link to post
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
Sign in to follow this  

×