Sign in to follow this  
Followers 0
DjDeep00

Guictrlsetdata for Date Control

4 posts in this topic

I am trying to update the "Start Date" by inputing it into the input field and hitting the change button. But I am not sure what I am doing wrong. Please help...

#include <GUIConstants.au3>

GUICreate("Date Test",300,200)
    
    $x=20
    $Label_Start_Date = GUICtrlCreateLabel("Start Date", 25, $x, 90, 20, 0x0200 + 0x01)
    $Start_Date = GUICtrlCreateDate(@MON & "/" & @MDAY & "/" & @YEAR, 115, $x, 100, 20)
    
    $x=$x+21
    $Label_End_Date = GUICtrlCreateLabel("End Date", 25, $x, 90, 20, 0x0200 + 0x01)
    $End_Date = GUICtrlCreateDate("", 115, $x, 100, 20)

    $DTM_SETFORMAT = 0x1032
    $style = "MM/dd/yyyy"
    GUICtrlSendMsg($Start_Date, $DTM_SETFORMAT, 0, $style)
    GUICtrlSendMsg($End_Date, $DTM_SETFORMAT, 0, $style)
    
    $x=$x+41
    $New_Date=GUICtrlCreateInput("",25,$x)
    $x=$x+21
    $Change_Button=GUICtrlCreateButton("Change",25,$x)
    
    
    GUISetState()


While 1
    $msg = GUIGetMsg()

    Select
      case $msg = $GUI_EVENT_CLOSE
        ExitLoop
        
      case $msg = $Change_Button
    GUICtrlSetData($Start_Date,GUICtrlRead($New_Date))

    EndSelect
Wend

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

The date has to be entered in a very specific format.

YYYY-MM-DD

Single digits must be zero padded.

This will get you started:

#include 

GUICreate("Date Test",300,200)
    
    $x=20
    $Label_Start_Date = GUICtrlCreateLabel("Start Date", 25, $x, 90, 20, 0x0200 + 0x01)
    $Start_Date = GUICtrlCreateDate(@MON & "/" & @MDAY & "/" & @YEAR, 115, $x, 100, 20)
    
    $x += 21
    $Label_End_Date = GUICtrlCreateLabel("End Date", 25, $x, 90, 20, 0x0200 + 0x01)
    $End_Date = GUICtrlCreateDate("", 115, $x, 100, 20)

    $DTM_SETFORMAT = 0x1032
    $style = "MM/dd/yyyy"
    GUICtrlSendMsg($Start_Date, $DTM_SETFORMAT, 0, $style)
    GUICtrlSendMsg($End_Date, $DTM_SETFORMAT, 0, $style)
    
    $x += 41
    
    $New_Date = GUICtrlCreateInput("",25,$x)
    
    $x += 21
    $Change_Button = GUICtrlCreateButton("Change",25,$x)
    
    
    GUISetState()


While 1
    Switch GUIGetMsg()
        case $GUI_EVENT_CLOSE
            ExitLoop
        
    case $Change_Button
        $A = StringSplit ( GUICtrlRead($New_Date), "/-")
        $VALIDDATE = StringFormat("%04d",$A[3]) & "-" & StringFormat("%02d",$A[1]) & "-" & StringFormat("%02d",$A[2])
        MsgBox(0,"",$VALIDDATE)
        GUICtrlSetData($Start_Date,$VALIDDATE)
    EndSwitch
Wend

This will allow you to enter dates like 8/5/2007 but if you want to use 2-digit year it will take some more work (to determine if it should be 19XX or 20XX)

Edited by weaponx

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I am trying to update the "Start Date" by inputing it into the input field and hitting the change button. But I am not sure what I am doing wrong. Please help...

#include <GUIConstants.au3>

GUICreate("Date Test",300,200)
    
    $x=20
    $Label_Start_Date = GUICtrlCreateLabel("Start Date", 25, $x, 90, 20, 0x0200 + 0x01)
    $Start_Date = GUICtrlCreateDate(@MON & "/" & @MDAY & "/" & @YEAR, 115, $x, 100, 20)
    
    $x=$x+21
    $Label_End_Date = GUICtrlCreateLabel("End Date", 25, $x, 90, 20, 0x0200 + 0x01)
    $End_Date = GUICtrlCreateDate("", 115, $x, 100, 20)

    $DTM_SETFORMAT = 0x1032
    $style = "MM/dd/yyyy"
    GUICtrlSendMsg($Start_Date, $DTM_SETFORMAT, 0, $style)
    GUICtrlSendMsg($End_Date, $DTM_SETFORMAT, 0, $style)
    
    $x=$x+41
    $New_Date=GUICtrlCreateInput("",25,$x)
    $x=$x+21
    $Change_Button=GUICtrlCreateButton("Change",25,$x)
    
    
    GUISetState()
While 1
    $msg = GUIGetMsg()

    Select
      case $msg = $GUI_EVENT_CLOSE
        ExitLoop
        
      case $msg = $Change_Button
    GUICtrlSetData($Start_Date,GUICtrlRead($New_Date))

    EndSelect
Wend

You have to use year/month/day regardless of the date format displayed.

GuiCtrlSetDat($tart_Date,"2007/08/16")

Beaten to it by weaponx, but you are wrong about the slashes weaponx.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

You have to use year/month/day regardless of the date format displayed.

GuiCtrlSetDat($tart_Date,"2007/08/16")

Beaten to it by weaponx, but you are wrong about the slashes weaponx.

I knew that, I was just making sure you knew it Martin. Lol...Thanx

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  
Followers 0