mapl Posted February 10, 2015 Share Posted February 10, 2015 (edited) expandcollapse popup#include <DateTimeConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #Include <Date.au3> HotKeySet("{ESC}", "Terminate") GUICreate("Look-Up Tool", 350, 120, -1, -1) Global $idDate = GUICtrlCreateDate("", 10, 10, 180, 20, $DTS_SHORTDATEFORMAT) ; Date Picker Global $idTime = GUICtrlCreateDate("", 10, 40, 180, 20, $DTS_TIMEFORMAT) ; Time Picker $DTM_SETFORMAT_ = 0x1032 $style = "HH:mm" GUICtrlSendMsg($idTime, $DTM_SETFORMAT_, 0, $style) Global $idCalculate = GUICtrlCreateButton("Calculate Date/Time", 10, 90, 330, 20) GUICtrlSetOnEvent($idCalculate, "Calculate") GUICtrlCreateLabel("Result", 245, 10) GUISetState(@SW_SHOW) Local $iMsg = 0 While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $idCalculate Calculate() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func Terminate() Exit 0 ; Terminate via ESC EndFunc Func Calculate() GUICtrlCreateLabel(GUICtrlRead($idDate), 235, 30) ; Display Date GUICtrlCreateLabel(GUICtrlRead($idTime), 235, 50) ; Display Time GUICtrlCreateLabel(_DateAdd('h', -4, GUICtrlRead($idTime)), 235, 70) ; Subtract 4 hours. EndFunc Program will basically subtract 4 hours from chosen date and time. Not sure why the line "GUICtrlCreateLabel(_DateAdd('h', -4, GUICtrlRead($idTime)), 235, 50) ; Subtract 4 hours." gives out "0". Any help will be appreciated. Edited February 10, 2015 by mapl Link to comment Share on other sites More sharing options...
water Posted February 10, 2015 Share Posted February 10, 2015 Because (according to the help file) _DateAdd needs the date and the time in format "YYYY/MM/DD[ HH:MM:SS]". My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
water Posted February 10, 2015 Share Posted February 10, 2015 BTW: Could you please enclose your code in AutoIt code tags (in the editor click on the blue "A" icon). That greatly enhances readability. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
iamtheky Posted February 10, 2015 Share Posted February 10, 2015 this would fix it, until a smart regexp shows up Func Calculate() GUICtrlCreateLabel(GUICtrlRead($idDate), 235, 30) ; Display Date GUICtrlCreateLabel(GUICtrlRead($idTime), 235, 50) ; Display Time $sMinus4hr = _DateAdd('h', -4, "2015/01/01 " & GUICtrlRead($idTime)) $aMinus4hr = stringsplit($sMinus4hr , " " , 3) GUICtrlCreateLabel($aMinus4hr[1], 235, 70) ; Subtract 4 hours. EndFunc ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
mapl Posted February 10, 2015 Author Share Posted February 10, 2015 Thanks @boththose Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 11, 2015 Moderators Share Posted February 11, 2015 Are you creating labels over and over intentionally, or would you prefer to only create 1 time and fill the data in? The method you're currently using is like having a memory leak. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Solution kylomas Posted February 11, 2015 Solution Share Posted February 11, 2015 (edited) mapl, Try this... expandcollapse popup#include <DateTimeConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #Include <Date.au3> HotKeySet("{ESC}", "Terminate") GUICreate("Look-Up Tool", 350, 120, -1, -1) Global $idDate = GUICtrlCreateDate("", 10, 10, 180, 20, $DTS_SHORTDATEFORMAT) ; Date Picker Global $idTime = GUICtrlCreateDate("", 10, 40, 180, 20, $DTS_TIMEFORMAT) ; Time Picker $DTM_SETFORMAT_ = 0x1032 $style = "HH:mm" GUICtrlSendMsg($idTime, $DTM_SETFORMAT_, 0, $style) Global $idCalculate = GUICtrlCreateButton("Calculate Date/Time", 10, 90, 330, 20) GUICtrlSetOnEvent($idCalculate, "Calculate") GUICtrlCreateLabel("Result", 245, 10) local $strt010 = guictrlcreatelabel('',245,30,100,20) local $diff010 = guictrlcreatelabel('',245,50,100,20) GUISetState(@SW_SHOW) Local $iMsg = 0 While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $idCalculate Calculate() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func Terminate() Exit 0 ; Terminate via ESC EndFunc Func Calculate() guictrlsetdata($strt010, guictrlread($idDate) & ' ' & guictrlread($idTime)) guictrlsetdata($diff010,_dateadd('h', -4, stringregexpreplace(guictrlread($idDate),'(\d+)/(\d+)/(\d\d\d\d)','$3/$1/$2') & ' ' & GUICtrlRead($idTime))) EndFunc DateAdd needs the date/time parm in a specific format. Also, as SmOke_N said, you are recreating controls needlessly. kylomas edit: Also the HotKey is not necessary to exit the script. Edited February 11, 2015 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
iamtheky Posted February 11, 2015 Share Posted February 11, 2015 also, this stringsplit syntax i am just getting used to Func Calculate() GUICtrlCreateLabel(GUICtrlRead($idDate), 235, 30) ; Display Date GUICtrlCreateLabel(GUICtrlRead($idTime), 235, 50) ; Display Time GUICtrlCreateLabel(stringsplit(_DateAdd('h', -4 , "2015/01/01" & " " & GUICtrlRead($idTime)), " " , 3)[1] , 235, 70) EndFunc ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
mapl Posted February 11, 2015 Author Share Posted February 11, 2015 Thanks everyone! 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