MrNumbers Posted February 28, 2014 Posted February 28, 2014 (edited) Hey there! I'm a little lost here... Long story short I'm trying to make a mini program to keep track of my hours at work - the code below had already been stripped down considerably, but leaves at least the main GUI intact. The problem here is with both of the "UpDown" controls/inputbox controls. I have wrote a mini function called "IntToTime" located at the bottom of the script to change the default output of the UpDown control (0,1,2,3,4,5,etc..) into (12:00 Am, 12:30 Am, 1:00 Am .... 4:30 Pm, 5:00 Pm, etc...) The problem is though... well let me describe it: Date is set to "27/02/2014", I set the times to "8:00 Am" and "1:00 Pm", I then change the date to "28/02/2014" which will reset both the times back to "12:00 Am". Although, now when I press Up on either of the UpDown controls, they won't go to "12:30 Am", but rather "8:30 Am" or "1:30 Pm" - same with the down buttons. Any help here on why this is happening? I've been messing around with this for hours now and it's driving me nuts expandcollapse popup#include <ButtonConstants.au3> #include <DateTimeConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiTreeView.au3> #include <File.au3> #include <Date.au3> #Include <Array.au3> Opt("GUIOnEventMode", 1) $Form1 = GUICreate("Hour Manager v1", 243, 281, 267, 240) GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close") $DateSelect = GUICtrlCreateMonthCal("", 8, 8, 229, 164) GUICtrlSetOnEvent(-1, "DateSelectChange") $Label1 = GUICtrlCreateLabel("Time Worked:", 8, 176, 71, 17) $StartTime = GUICtrlCreateInput("12:00 Am", 16, 200, 73, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_READONLY)) $Updown1 = GUICtrlCreateUpdown($StartTime) GUICtrlSetLimit(-1, 47, 0) GUICtrlSetOnEvent(-1, "Updown1Change") $Label2 = GUICtrlCreateLabel("To", 112, 200, 17, 17) $EndTime = GUICtrlCreateInput("12:00 Am", 168, 200, 73, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_READONLY)) $Updown2 = GUICtrlCreateUpdown($EndTime) GUICtrlSetLimit(-1, 47, 0) GUICtrlSetOnEvent(-1, "Updown2Change") $Checkbox1 = GUICtrlCreateCheckbox("Worked This Day", 128, 176, 105, 17) $Button = GUICtrlCreateButton("Open Total Time Worked", 48, 248, 145, 25) $Label3 = GUICtrlCreateLabel("Hours Worked This Week (Sun-Sat):", 8, 224, 178, 17) $Label4 = GUICtrlCreateLabel("0", 192, 224, 10, 17) GUISetState(@SW_SHOW) global $SaveDir = @ScriptDir & "\Saved Hours\",$StartVar,$EndVar,$DateArray,$Force AdLibRegister("ForceUpdate",100) While 1 Sleep(100) WEnd Func Form1Close() Exit EndFunc Func DateSelectChange() UpdateGUI() EndFunc Func Updown1Change() $StartVar = GUICtrlRead($StartTime) GUICtrlSetData($StartTime, IntToTime(GUICtrlRead($StartTime))) EndFunc Func Updown2Change() $EndVar = GUICtrlRead($EndTime) GUICtrlSetData($EndTime, IntToTime(GUICtrlRead($EndTime))) EndFunc Func UpdateGUI() $DateArray = stringsplit(GUICtrlRead($DateSelect), "/") $StartVar = iniread($SaveDir & $DateArray[1] & ".ini", $DateArray[2], $DateArray[3] & "-S", "-1") $EndVar = iniread($SaveDir & $DateArray[1] & ".ini", $DateArray[2], $DateArray[3] & "-E", "-1") If $StartVar <> -1 Then GUICtrlSetData($StartTime, IntToTime($StartVar)) GUICtrlSetData($EndTime, IntToTime($EndVar)) GUICtrlSetState($Checkbox1, $GUI_CHECKED) Else $StartVar = 0 $EndVar = 0 GUICtrlSetData($StartTime, IntToTime(0)) GUICtrlSetData($EndTime, IntToTime(0)) GUICtrlSetState($Checkbox1, $GUI_UNCHECKED) EndIf EndFunc Func ForceUpdate() If $Force <> GUICtrlRead($DateSelect) Then $Force = GUICtrlRead($DateSelect) UpdateGUI() EndIf EndFunc Func IntToTime($InputHours) Local $AmPm, $Half If $InputHours < 24 Then $AmPm = 0 Else $AmPm = 1 $InputHours = $InputHours - 24 EndIf If Mod($InputHours, 2) = 0 Then $Half = 0 Else $Half = 1 $InputHours = $InputHours - 1 EndIf If $InputHours = 0 Then $InputHours = 24 EndIf If $Half = 0 Then If $AmPm = 0 Then Return $InputHours / 2 & ":00 Am" Else Return $InputHours / 2 & ":00 Pm" EndIf Else If $AmPm = 0 Then Return $InputHours / 2 & ":30 Am" Else Return $InputHours / 2 & ":30 Pm" EndIf EndIf EndFunc Oh, I have also tried setting the values of both the inputbox and the updown controls to 0 first before changing it to "12:00 Am", yet it does not work. Also will note, I think the problem lies @ lines 73/74: GUICtrlSetData($StartTime, IntToTime(0)) GUICtrlSetData($EndTime, IntToTime(0)) I have tried setting them to GUICtrlSetData($StartTime, 0) GUICtrlSetData($EndTime, 0) Which DOES in fact, fix the problem. Although I'd really like to have them display the "12:00 Am" rather than "0"... : Edited February 28, 2014 by MrNumbers
Moderators Solution Melba23 Posted February 28, 2014 Moderators Solution Posted February 28, 2014 MrNumbers,The problem seems to arise because you are setting the input content to a non-numeric value which is not recognised by the UpDown - testing the content of the input when the UpDown is used shows that it is just altering by 1 each time and not being reset when you change the date string.My solution would be to use a separate dummy input to hold the UpDown which maintains this integer value and place the "time" string into the original - like this:expandcollapse popup#include <ButtonConstants.au3> #include <DateTimeConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiTreeView.au3> #include <File.au3> #include <Date.au3> #include <Array.au3> Opt("GUIOnEventMode", 1) $Form1 = GUICreate("Hour Manager v1", 243, 281, 267, 240) GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close") $DateSelect = GUICtrlCreateMonthCal("", 8, 8, 229, 164) GUICtrlSetOnEvent(-1, "DateSelectChange") $Label1 = GUICtrlCreateLabel("Time Worked:", 8, 176, 71, 17) $StartTime = GUICtrlCreateInput("12:00 Am", 16, 200, 60, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_READONLY)) $StartTime_Dummy = GUICtrlCreateInput(0, 76, 200, 16, 21) ; Dummy to hold UpDown <<<<<<<<<<<<<<<<<<<< $Updown1 = GUICtrlCreateUpdown($StartTime_Dummy) GUICtrlSetLimit(-1, 47, 0) GUICtrlSetOnEvent(-1, "Updown1Change") $Label2 = GUICtrlCreateLabel("To", 112, 200, 17, 17) $EndTime = GUICtrlCreateInput("12:00 Am", 158, 200, 60, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_READONLY)) $EndTime_Dummy = GUICtrlCreateInput(0, 218, 200, 16, 21) $Updown2 = GUICtrlCreateUpdown($EndTime_Dummy) GUICtrlSetLimit(-1, 47, 0) GUICtrlSetOnEvent(-1, "Updown2Change") $Checkbox1 = GUICtrlCreateCheckbox("Worked This Day", 128, 176, 105, 17) $Button = GUICtrlCreateButton("Open Total Time Worked", 48, 248, 145, 25) $Label3 = GUICtrlCreateLabel("Hours Worked This Week (Sun-Sat):", 8, 224, 178, 17) $Label4 = GUICtrlCreateLabel("0", 192, 224, 10, 17) GUISetState(@SW_SHOW) Global $SaveDir = @ScriptDir & "\Saved Hours\", $StartVar, $EndVar, $DateArray, $Force AdlibRegister("ForceUpdate", 100) While 1 Sleep(100) WEnd Func Form1Close() Exit EndFunc ;==>Form1Close Func DateSelectChange() UpdateGUI() EndFunc ;==>DateSelectChange Func Updown1Change() GUICtrlSetData($StartTime, IntToTime(GUICtrlRead($StartTime_Dummy))) ; Read dummy <<<<<<<<<<<<<<<<<<<< EndFunc ;==>Updown1Change Func Updown2Change() GUICtrlSetData($EndTime, IntToTime(GUICtrlRead($EndTime_Dummy))) ; Read dummy <<<<<<<<<<<<<<<<<<<< EndFunc ;==>Updown2Change Func UpdateGUI() $DateArray = StringSplit(GUICtrlRead($DateSelect), "/") $StartVar = IniRead($SaveDir & $DateArray[1] & ".ini", $DateArray[2], $DateArray[3] & "-S", "-1") $EndVar = IniRead($SaveDir & $DateArray[1] & ".ini", $DateArray[2], $DateArray[3] & "-E", "-1") If $StartVar <> -1 Then GUICtrlSetData($StartTime, IntToTime($StartVar)) GUICtrlSetData($EndTime, IntToTime($EndVar)) GUICtrlSetState($Checkbox1, $GUI_CHECKED) Else $StartVar = 0 $EndVar = 0 GUICtrlSetData($StartTime, IntToTime(0)) GUICtrlSetData($EndTime, IntToTime(0)) GUICtrlSetState($Checkbox1, $GUI_UNCHECKED) EndIf EndFunc ;==>UpdateGUI Func ForceUpdate() If $Force <> GUICtrlRead($DateSelect) Then $Force = GUICtrlRead($DateSelect) GUICtrlSetData($StartTime_Dummy, 0) ; Reset dummy <<<<<<<<<<<<<<< GUICtrlSetData($EndTime_Dummy, 0) ; Reset dummy <<<<<<<<<<<<<<< UpdateGUI() EndIf EndFunc ;==>ForceUpdate Func IntToTime($iInput) ; New function <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Local $iHours = Mod(Int($iInput / 2), 12) If $iHours = 0 Then $iHours = 12 Local $iHalf = Mod($iInput, 2) If $iHalf Then $iHalf = ":30" Else $iHalf = ":00" EndIf Switch $iInput Case 0 To 23 $sSuffix = " AM" Case Else $sSuffix = " PM" EndSwitch Return $iHours & $iHalf & $sSuffix EndFunc ;==>IntToTimeThat way when you reset the dummy on a date change everything runs as it should. The IniRead section will obviously need changing, but that should not be insurmountable - let me know if I can help sort it out. 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
MrNumbers Posted February 28, 2014 Author Posted February 28, 2014 Aha! I was gonna mess around with dummy controls a bit - though considering how tired I was yesterday I just couldn't wrap my head around it all I also see you re-wrote my super sloppy TimeToInt command, I was gonna get around to doing that but considering it "Worked" I didn't bother, heh. Thanks a bunch though! Works great now
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