Thingy2nl Posted January 26, 2013 Posted January 26, 2013 Gents, As a complete n00b, i have been breaking my teeth on a, i presume, rather basic issue with a date variabele. It must be simple as I can't find an answer anywhere... and trust me, i've looked and googled but to no avail.... I am trying to build a pretty basic GUI that let's the user input some directory paths, radio buttons, list items, text fields and a date. No problem so far. Then the user can push a button to save thee settings, and all chooses are save to an ini file for later retrieval.... so far, still no problem... At some point in time, the user elects to load the ini file, and that's were i run into a mess with a date field... Here's what i do, i preselect the current date: Global $sShowday = @YEAR & "/" & @MON & "/" & @MDAY GUICtrlCreateLabel("Datum show", 332, 98, 168, 21) ;Datum show $sShowday = GUICtrlCreateDate($sShowday, 444, 98, 281, 21) User selects f.i. zaterdag 26 januari 2013 (as shown on screen. This format is not on purpose, but i do like it as it helps verifying the date. Most days will be sunday's. Willing to change is needbe) user selects to save: $var = IniWrite(@ScriptDir & "\Certificate.ini", "Show_date", "sShowday", GUICtrlRead($sShowday)) Ini reads: [show_date] sShowday=zaterdag 26 januari 2013 Then i try to read it back with: $var = IniRead(@ScriptDir & "\Certificate.ini", "Show_date", "sShowday", "ERROR") GUICtrlSetData($sShowday, $var) But this fails..... because $var is not in yyyy/mm/dd format. If i use: GUICtrlSetData($sShowday, "2014/01/01") It works fine. So the actual question is, how do i get the date that is saved, in the yyyy/mm/dd format.... I tried different way's to save like: $var = IniWrite(@ScriptDir & "\Certificate.ini", "Show_date", "sShowday", _DateCalc(GUICtrlRead($sShowday), "YYYYMMDD")) I tried different way's to input the date like: $sShowday = GUICtrlCreateDate($sShowday, 444, 98, 281, 21, $GUI_SS_DEFAULT_DATE) but so far nothing worked.... I just want to input a date, save it, read it back and put it back on the screen..... Any help or pointers or examples are very welcome.... Michiel
Realm Posted January 27, 2013 Posted January 27, 2013 Does the actual day of the week need to be stored, or can it be inputted at time of control creation/update? If the later is possible, I'd suggest storing just the date in your file, then have your script determine the day with _DateDayOfWeek() function provided with your help file in 'Date Management' under the 'User Defined Functions Reference' section to post with your GUI. Happy Coding! Realm My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.
kylomas Posted January 27, 2013 Posted January 27, 2013 (edited) Thingy2nl, You are creating a variable called $sShowday, populating it with the date then overwritting it as a control id for the date control. This works for me (if I understand what you are doing). expandcollapse popup; *** Start added by AutoIt3Wrapper *** #include <Constants.au3> ; *** End added by AutoIt3Wrapper *** ; *** Start added by AutoIt3Wrapper *** #include <StaticConstants.au3> ; *** End added by AutoIt3Wrapper *** ; *** Start added by AutoIt3Wrapper *** #include <GUIConstantsEx.au3> ; *** End added by AutoIt3Wrapper *** #AutoIt3Wrapper_Add_Constants=n Global $sShowday = @YEAR & "/" & @MON & "/" & @MDAY local $gui010 = guicreate('INI Date Save Example',400,400) GUICtrlCreateLabel('Datum', 10, 20, 150, 20) local $lbl010 = GUICtrlCreateLabel('', 10, 40, 200, 20,$ss_sunken) guictrlsetfont(-1,8.5,800,-1,'Luciinda Console') local $dte010 = GUICtrlCreateDate($sShowday, 10, 70, 250, 20) local $btn010 = GUICtrlCreatebutton('Save Settings',10,320,380,20) local $btn020 = GUICtrlCreatebutton('Restore Settings',10,350,380,20) guisetstate() guictrlsetdata($lbl010,guictrlread($dte010)) while 1 switch guigetmsg() case $gui_event_close exit case $dte010 guictrlsetdata($lbl010,guictrlread($dte010)) case $btn010 $var = IniWrite(@ScriptDir & "\Certificate.ini", "Show_date", "sShowday", GUICtrlRead($dte010)) if $var <> 1 then msgbox($mb_ok,'INI WRITE ERROR','') case $btn020 $var = Iniread(@ScriptDir & "\Certificate.ini", "Show_date", "sShowday", "ERROR") if $var = "ERROR" then msgbox($mb_ok,'INI DATE READ ERROR','') guictrlsetdata($lbl010,$var) EndSwitch wend Good Luck, kylomas edit: spelling Edited January 27, 2013 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
Thingy2nl Posted January 27, 2013 Author Posted January 27, 2013 Kylomas, You are correct, this works, but how would I go about putting the date that was read from the inifile back into the $dte010 and update the GUICtrlCreateDate($sShowday, 10, 70, 250, 20) control?
Thingy2nl Posted January 27, 2013 Author Posted January 27, 2013 Does the actual day of the week need to be stored, or can it be inputted at time of control creation/update?The day does not have to be stored. I like the fact that the input control shows it, but in the end, I only need a date. It's just that i can't figure out how the store the date and then put it back into the original control to show the user that the date was read from file (and current settings are updated).
kylomas Posted January 27, 2013 Posted January 27, 2013 (edited) Thingy2nl, The code that I posted does just that. Get a date (other than todays date from the date control and press the "Save Settings" button and it will write the date to an ini file. Change the date again to some other date. Then press the "Restore Settings" button and you will see the date refreshed from the ini file. This code is an example of how to do what you were reporting as a problem. Adapt it however you want. kylomas edit: additional data Then just strip the day off while you have it in a variable. Edited January 27, 2013 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
kylomas Posted January 27, 2013 Posted January 27, 2013 Thingy2nl, I altered the code to try to save back to the date control. However, it is failing for some reason that I do not understand. Perhaps one of the GUI experts will weigh in on this. Failing code with comments: expandcollapse popup; *** Start added by AutoIt3Wrapper *** #include <Constants.au3> ; *** End added by AutoIt3Wrapper *** ; *** Start added by AutoIt3Wrapper *** #include <StaticConstants.au3> ; *** End added by AutoIt3Wrapper *** ; *** Start added by AutoIt3Wrapper *** #include <GUIConstantsEx.au3> ; *** End added by AutoIt3Wrapper *** #AutoIt3Wrapper_Add_Constants=n Global $sShowday = @YEAR & "/" & @MON & "/" & @MDAY, $ret local $gui010 = guicreate('INI Date Save Example',400,400) GUICtrlCreateLabel('Datum', 10, 20, 150, 20) local $lbl010 = GUICtrlCreateLabel('', 10, 40, 200, 20,$ss_sunken) guictrlsetfont(-1,8.5,800,-1,'Luciinda Console') local $dte010 = GUICtrlCreateDate('', 10, 70, 250, 20) local $btn010 = GUICtrlCreatebutton('Save Settings',10,320,380,20) local $btn020 = GUICtrlCreatebutton('Restore Settings',10,350,380,20) guisetstate() guictrlsetdata($lbl010,guictrlread($dte010)) while 1 switch guigetmsg() case $gui_event_close exit case $dte010 guictrlsetdata($lbl010,guictrlread($dte010)) case $btn010 $var = IniWrite(@ScriptDir & "\Certificate.ini", "Show_date", "sShowday", GUICtrlRead($dte010)) if $var <> 1 then msgbox($mb_ok,'INI WRITE ERROR','') case $btn020 $var = Iniread(@ScriptDir & "\Certificate.ini", "Show_date", "sShowday", "ERROR") if $var = "ERROR" then msgbox($mb_ok,'INI DATE READ ERROR','') ConsoleWrite($var & @LF) $ret = guictrlsetdata($dte010,$var) ; <----------- this does not appear to work ConsoleWrite($ret & @LF) ; <----------- returns "0" - failure...not sure why guictrlsetdata($lbl010,$var) EndSwitch wend 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
kylomas Posted January 27, 2013 Posted January 27, 2013 Thingy2nl,I found thread, maybe that will help!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
Thingy2nl Posted January 27, 2013 Author Posted January 27, 2013 Thingy2nl,I altered the code to try to save back to the date control. However, it is failing for some reason that I do not understand. Perhaps one of the GUI experts will weigh in on this. Failing code with comments:Kewl.... so i'm not completely of my rockers Thank's for trying to fix this. Let's hope someone has a solution. I allready though of placing multiple field over one another ans in stead of moving the date back to the original control, just show the overlapping field. But there has to be a simpler way....
Thingy2nl Posted January 27, 2013 Author Posted January 27, 2013 Thingy2nl,I found thread, maybe that will help!kylomasLook promessing.... gone dive right in..... Thank's for the link.
kylomas Posted January 27, 2013 Posted January 27, 2013 (edited) Thingy2nl, Changing the date style works a demonstrated by the God of Gui's (M23). You were on the right track, the "day" was causing the problem. This code works: expandcollapse popup; *** Start added by AutoIt3Wrapper *** #include <Constants.au3> ; *** End added by AutoIt3Wrapper *** ; *** Start added by AutoIt3Wrapper *** #include <StaticConstants.au3> ; *** End added by AutoIt3Wrapper *** ; *** Start added by AutoIt3Wrapper *** #include <GUIConstantsEx.au3> ; *** End added by AutoIt3Wrapper *** #AutoIt3Wrapper_Add_Constants=n Global $sShowday = @YEAR & "/" & @MON & "/" & @MDAY, $ret, $DTM_SETFORMAT_ = 0x1032 ; $DTM_SETFORMATW < ------ added this local $gui010 = guicreate('INI Date Save Example',400,400) GUICtrlCreateLabel('Datum', 10, 20, 150, 20) local $lbl010 = GUICtrlCreateLabel('', 10, 40, 200, 20,$ss_sunken) guictrlsetfont(-1,8.5,800,-1,'Luciinda Console') local $dte010 = GUICtrlCreateDate('', 10, 70, 250, 20) local $btn010 = GUICtrlCreatebutton('Save Settings',10,320,380,20) local $btn020 = GUICtrlCreatebutton('Restore Settings',10,350,380,20) guisetstate() guictrlsetdata($lbl010,guictrlread($dte010)) while 1 switch guigetmsg() case $gui_event_close exit case $dte010 guictrlsetdata($lbl010,guictrlread($dte010)) case $btn010 local $sStyle = "yyyy/MM/dd" ; <---- added this GUICtrlSendMsg($dte010, $DTM_SETFORMAT_, 0, $sStyle) ; <---- added this $var = IniWrite(@ScriptDir & "\Certificate.ini", "Show_date", "sShowday", GUICtrlRead($dte010)) if $var <> 1 then msgbox($mb_ok,'INI WRITE ERROR','') case $btn020 $var = Iniread(@ScriptDir & "\Certificate.ini", "Show_date", "sShowday", "ERROR") if $var = "ERROR" then msgbox($mb_ok,'INI DATE READ ERROR','') ConsoleWrite($var & @LF) $ret = guictrlsetdata($dte010,$var) ConsoleWrite($ret & @LF) guictrlsetdata($lbl010,$var) EndSwitch wend kylomas edit: forgot to credit BrewmanNH from the thread I pointed to. Edited January 27, 2013 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
Thingy2nl Posted January 27, 2013 Author Posted January 27, 2013 kylomas, It's a good thing you are not within my reach for i might have to kiss you! With the first example from the link, i managed to solve my issue. In hindside it is pretty simple.... What I did is: Define 2 date formats, 1 that looks nice, 1 that i need to store my dates. Not sure about what the 0x1032 does, but will look into that tomorrow. $DTM_SETFORMAT_ = 0x1032 ;$DTM_SETFORMATW Global $sLongDate = "dddd dd MMMM yyyy" Global $sShortDate = "yyyy/MM/dd" Then send the date control to the gui and force is in the correct format from the start: $sShowday = GUICtrlCreateDate($sShowday, 444, 98, 281, 21) GUICtrlSendMsg($sShowday, $DTM_SETFORMAT_, 0, $sLongDate) Just before saving I change the date control to the format I need, read/save and change it back to the long format: GUICtrlSendMsg($sShowday, $DTM_SETFORMAT_, 0, $sShortDate) $var = IniWrite(@ScriptDir & "\Certificate.ini", "Show_date", "sShowday", GUICtrlRead($sShowday)) GUICtrlSendMsg($sShowday, $DTM_SETFORMAT_, 0, $sLongDate) By now, it is in the ini file in the correct format: [Show_date] sShowday=2013/01/13 And restoring is just reading it back like: $var = IniRead(@ScriptDir & "\Certificate.ini", "Show_date", "sShowday", "ERROR") GUICtrlSetData($sShowday, $var) Could defenately not have done this without that example.... So again, thank's for you help. Hope I can do the same for someone else someday.... Thingy
kylomas Posted January 27, 2013 Posted January 27, 2013 Excellent, we both learned something today. 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
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