Freedom1 Posted April 22, 2009 Share Posted April 22, 2009 Hello All, I'm confused in how to use the DTP selected date. Here's my situation. I have a DTP control on my form. The date in the DTP is displayed as "Wed, April 22, 2009". The user then presses a button and now I want to format that selected date into another text input control and several $variables. I can convert to a text input control using the following code although it looks like a hack ($Date1F is the DTP control and $Date1Name is the text input control). $style = "MMddyy" GUICtrlSendMsg($Date1F, $DTM_SETFORMAT_, 0, $style) GUICtrlSetData($Date1Name, GUICtrlRead($Date1F)) Now I want to change the format of the DTP selected date to various $variables in the following formats. $var1 - mmddyy 042209 $var2 - yyyymmdd 20090422 $var3 - mmm dd April 22 $var4 - yymmdd-constant 090422-SummaryReport The GUICtrlRead returns the selected date in the exact same way as it is displayed in the DTP. There has to be a cleaner and more efficient way to convert the formats of the dates. I've checked the forums and tried _DateTimeFormat but couldn't get it to work properly. Please assist and point me in the right direction. Freedom1 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 22, 2009 Moderators Share Posted April 22, 2009 Freedom1,I think this does what you want:expandcollapse popup#include <GUIConstantsEx.au3> #Include <GuiDateTimePicker.au3> #include <WindowsConstants.au3> #include <Date.au3> Global $fFlag = False, $aTime[8] $hGUI = GUICreate("Test", 500, 500) $hDTP = _GUICtrlDTP_Create($hGUI, 10, 10) $hLabel1 = GUICtrlCreateLabel("", 10, 50, 300, 20) $hLabel2 = GUICtrlCreateLabel("", 10, 80, 300, 20) $hLabel3 = GUICtrlCreateLabel("", 10, 110, 300, 20) $hLabel4 = GUICtrlCreateLabel("", 10, 140, 300, 20) GUIRegisterMsg($WM_NOTIFY, "MY_WM_NOTIFY") GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch If $fFlag Then GUICtrlSetData($hlabel1, StringFormat("%02s", $aTime[0]) & StringFormat("%02s", $aTime[1]) & StringRight($aTime[2], 2)) GUICtrlSetData($hlabel2, $aTime[2] & StringFormat( "%02s", $aTime[0]) & StringFormat("%02s", $aTime[1])) GUICtrlSetData($hlabel3, _DateToMonth($aTime[0]) & " " & StringFormat("%02s", $aTime[1])) GUICtrlSetData($hlabel4, StringRight($aTime[2], 2) & StringFormat("%02s", $aTime[1]) & StringFormat("%02s", $aTime[0]) & "-SummaryReport") $fFlag = False Endif WEnd Func MY_WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tBuffer, $tBuffer2 $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hDTP Switch $iCode Case $DTN_DATETIMECHANGE; Sent by a date and time picker (DTP) control whenever a change occurs $tInfo = DllStructCreate($tagNMDATETIMECHANGE, $ilParam) $aTime = _Date_Time_SystemTimeToArray($tInfo) $fFlag = True Return 0 EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>MY_WM_NOTIFYThe labels wil change when the DTP changes. The formatting part is in the GUICtrlSetData statements.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 23, 2009 Moderators Share Posted April 23, 2009 Freedom1,A different way to do it, using the bult-in Date control. You have to press the button to get the labels to update here, but that might be seen as an feature rather than a bug: ;-)expandcollapse popup#include <GUIConstantsEx.au3> #include <DateTimeConstants.au3> #include <WindowsConstants.au3> #include <Date.au3> $hGUI = GUICreate("Test", 500, 500) $date = GUICtrlCreateDate("", 10, 10, 200, 20) $hLabel1 = GUICtrlCreateLabel("", 10, 50, 300, 20) $hLabel2 = GUICtrlCreateLabel("", 10, 80, 300, 20) $hLabel3 = GUICtrlCreateLabel("", 10, 110, 300, 20) $hLabel4 = GUICtrlCreateLabel("", 10, 140, 300, 20) $hButton = GUICtrlCreateButton("Display", 10, 200, 80, 30) GUISetState() GUICtrlSendMsg($date, 0x1032, 0, "ddMMMMyy") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton GUICtrlSendMsg($date, 0x1032, 0, "MMddyy") GUICtrlSetData($hlabel1, GUICtrlRead($date)) GUICtrlSendMsg($date, 0x1032, 0, "yyyyMMdd") GUICtrlSetData($hlabel2, GUICtrlRead($date)) GUICtrlSendMsg($date, 0x1032, 0, "dd MMMM") GUICtrlSetData($hlabel3, GUICtrlRead($date)) GUICtrlSendMsg($date, 0x1032, 0, "yyMMdd") GUICtrlSetData($hlabel4, GUICtrlRead($date) & "-Summary Report") GUICtrlSendMsg($date, 0x1032, 0, "ddMMMMyy") EndSwitch WEndM23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Freedom1 Posted April 24, 2009 Author Share Posted April 24, 2009 Melba23, Thanks for your response. Just got back on it today. I prefer to use option 1. Using option 2 would add another button which may clutter the screen or cause confustion. Choices are good! Its exactly what I'm looking for. Thank you. I've seen the "MY_WM_NOTIFY" function in other snippets of AutoIt code in the forums. Is there a particular thread or location that I can read about the uses of it? Thanks again, Freedom1 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 24, 2009 Moderators Share Posted April 24, 2009 Freedom1,Delighted to help.Read about GUIRegisterMsg in the Help file to learn more about how to harness Windows messages. Other than that it is a question of learning from examples - just like I did!M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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