Diana (Cda) Posted January 6, 2011 Share Posted January 6, 2011 (edited) From this page, I found a great date picker a few days ago. I tweaked it some: expandcollapse popup#cs - SOURCE: 2011-01-01 07:57:08 (http://www.autoitscript.com/forum/topic/50952-date-box) #ce ; ; AutoIt 3x ; #NoTrayIcon ; AutoIt's icon doesn't show in systray TraySetIcon(@ScriptDir & "\DATE PICKER (2cb).ico") ; changes the icon displayed in the systray ;------------------------------------------------------------------------------------------------------------------------- #include <GUIConstants.au3> GUICreate("Date Picker (and sends to the Clipboard") $datebox = GUICtrlCreateDate("", 50, 40, 190, 20, "yyyy.mm.dd.ddd") ; original dimensions of box displaying date = 10, 40, 185, 20 - left, top, box width, box height $Button_1 = GUICtrlCreateButton ("To the clipboard ...", 50, 250, 175) ; original dimensions = 10, 70, 100 - left, top, button width GUISetState() ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 $date=Format_date($datebox) ; MsgBox(0,"Time", GUICtrlRead($date)) ClipPut(GUICtrlRead($date)) EndSelect Wend Func Format_date ($date) ;-------------------------------------- ; to select a specific default format $DTM_SETFORMAT = 0x1032 Sleep(350) ;$style = "dddd, MMMM dd, yyyy" ; this was original date format $style = "yyyy.MM.dd.ddd" ;-------------------------------------- GuiCtrlSendMsg($date, $DTM_SETFORMAT, 0, $style) ;MsgBox(0,"Time", GUICtrlRead($date)) Return $date EndFunc At the line $datebox = GUICtrlCreateDate, I found the instructions on GUICtrlCreateDate (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateDate.htm) that showed how to change the display format. I couldn't find the style format I needed to so I tried what I use: yyyy.mm.dd.ddd (as shown in script above). The date display is closer to my format, however, it doesn't display properly on first launching. It shows only as yyyy.mm.dd, missing out the .ddd (.Tue). After picking the date, the second date format where again I used yyyy.mm.dd.ddd format, _then_ it does show the date properly incl. the day in .ddd format. Was wondering what's up with this. Anyone know? Secondly, I don't know what controls buttons on this GUI. I tried adding a cancel button below the $Button_1 above and named it $Button_2 and added a Cancel_click with command but unlike regular GUIs, pushing that button doesn't do anything. Was wondering what I'm doing wrong here. Here are the 2 pieces of code that I've added to the test one with a cancel button: $Button_2 = GUICtrlCreateButton("Cancel", 300, 350, 75) ; left, top, button width GUICtrlSetOnEvent(-1, "Cancel_Click") Func Cancel_Click() Exit ; finished EndFunc Thanks for any help re this. Edited January 6, 2011 by Diana (Cda) Link to comment Share on other sites More sharing options...
LurchMan Posted January 6, 2011 Share Posted January 6, 2011 (edited) Secondly, I don't know what controls buttons on this GUI. I tried adding a cancel button below the $Button_1 above and named it $Button_2 and added a Cancel_click with command but unlike regular GUIs, pushing that button doesn't do anything. Was wondering what I'm doing wrong here. Here are the 2 pieces of code that I've added to the test one with a cancel button: $Button_2 = GUICtrlCreateButton("Cancel", 300, 350, 75) ; left, top, button width GUICtrlSetOnEvent(-1, "Cancel_Click") Func Cancel_Click() Exit ; finished EndFunc Thanks for any help re this. For the second part add this to the top of your script: Change: Case $msg = $GUI_EVENT_CLOSE To: Case $msg = $GUI_EVENT_CLOSE Or $msg = $Button_2 And get rid oft he Function. If you want to use functions then add: Opt("GUIOnEventMode", 1) To the top of your script, break each case statement into a function and add GUICtrlSetOnEvent for each control. Edited January 6, 2011 by LurchMan Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end. Link to comment Share on other sites More sharing options...
Bowmore Posted January 7, 2011 Share Posted January 7, 2011 (edited) This should help with setting the date time format on a date picker and demonstrates some of the formats that can be used #include <GuiDateTimePicker.au3> #include <Date.au3> $hGui = GUICreate("Date Test") $hdate = GUICtrlCreateDate(_Now(), 20,20, 250, 20, 0x00) $hWndDate = ControlGetHandle($hGui, "", $hdate) _GUICtrlDTP_SetFormat($hWndDate, "yyyy.MM.dd.ddd dddd HH:mm:ss tthh:mm.ss") ;<<=== of course you would not normally use such a mix of styles - this is just to show some possibilities GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case -3 Exit Case $hdate MsgBox(0, "Selected Date", GUICtrlRead($hdate)) EndSwitch WEnd Edited January 7, 2011 by Bowmore "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
Diana (Cda) Posted January 16, 2011 Author Share Posted January 16, 2011 Thanks everyone. Will take a look at both things. I'm pleased with the scripts so far but I really need how to configure the outputs better since I still do a lot of manual editing on the results. Too, just when I'm getting comfortable with GUIs, a format comes along that is much simpler-looking so I can't work things out by myself without some help <lol>. Cheers, Link to comment Share on other sites More sharing options...
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