ArkiePazi Posted August 23, 2011 Share Posted August 23, 2011 Hi, I have run into yet another problem considering time. The situation is this. I have a meter that adds 1 score per 5 minutes. The max cap is dynamic (configurable). The meter works and all but now I would like to have a clock that tells me how long it is until meter is full. It's hard because of the unknown max cap. And one more thing. It can't be just any 5 minutes, it need to be based on the computers clock, so that every 5 minutes is like 13:05, 13:10, 13:15 and so on. I hope this is doable. I have tried several things and always come to a dead end. A little simplified code to demonstrate what I'm trying to do. expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form3 = GUICreate("Form1", 117, 87, 310, 266) $Label1 = GUICtrlCreateLabel("Score:", 16, 16, 36, 17) $Label2 = GUICtrlCreateLabel("0/0", 64, 16, 36, 17) ; Score/max $Label3 = GUICtrlCreateLabel("", 32, 48, 52, 17) ; Time left until full GUISetState(@SW_SHOW) $Htime = @HOUR $Mtime = @MIN $Stime = @SEC $RCL = 0 ;---------------- $MaxScore = 25 ; configurable ;---------------- While 1 $1sec1 = @SEC $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch $1sec2 = @SEC If $1sec2 > $1sec1 Then ; Do stuff each second to save cpu power and stop flickering _Clock() ; just updates the clock _5minutespass() ; Gives a score every 5 minutes. EndIf WEnd Func _Clock () $Htime = @HOUR $Mtime = @MIN $Stime = @SEC EndFunc Func _5minutespass () $5min = @MIN $5sec = @SEC If $5min = 00 or $5min = 05 or $5min = 10 or $5min = 15 or $5min = 20 or $5min = 25 or $5min = 30 or $5min = 35 or $5min = 40 or $5min = 45 or $5min = 50 or $5min = 55 Then If $5sec = 01 Then $RCL = $RCL + 1 GUICtrlSetData($Label2,$RCL&"/"&$MaxScore) _MaxRat() EndIf EndIf EndFunc Func _MaxRat() ; tells when meter is full If $RCL = $MaxScore Then MsgBox(0,"Full!","The meter is full.") EndIf EndFunc Thank you in Advance. Link to comment Share on other sites More sharing options...
Blue_Drache Posted August 23, 2011 Share Posted August 23, 2011 $maxScore is user entered field via inputbox or something, right? Multiply max score by 5 ... that's going to be your maximum time. Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
ArkiePazi Posted August 23, 2011 Author Share Posted August 23, 2011 (edited) Thank you for your answer. Yes it is an input. If I insert, say, 25. 25*5 = 125. So 125 minutes left. The question is how I convert those 125 minutes to a clock format, like 00:00:00. EDIT: And then the issue that the score is based on the clocks 5 minutes. so I need to base all this on the computers clock not just 5 minutes from anywhere. If I start, lets say, 13:13 then the first score is given after just 2 minutes. Edited August 23, 2011 by ArkiePazi Link to comment Share on other sites More sharing options...
smashly Posted August 23, 2011 Share Posted August 23, 2011 Hi, Have a look in AutoIt help file under User Defined Function Reference -> Date Management -> _TimeToTicks and _TicksToTime. Also maybe look at Functions Reference -> String Management -> StringFormat so you can present your time formatted nicely. Cheers Link to comment Share on other sites More sharing options...
ArkiePazi Posted August 24, 2011 Author Share Posted August 24, 2011 I Just can't get it to work. I have tried many things with _TicksToTime, _TimeToTicks, _NowCalc and _AddDate. It felt like I got it but then just dead end. This is my latest try: expandcollapse popup#Include <Date.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form3 = GUICreate("Form1", 117, 87, 310, 266) $Label1 = GUICtrlCreateLabel("Score:", 16, 16, 36, 17) $Label2 = GUICtrlCreateLabel("0/0", 64, 16, 36, 17) ; Score/max $Label3 = GUICtrlCreateLabel("", 32, 48, 52, 17) ; Time left until full GUISetState(@SW_SHOW) Global $Sec, $Min, $Hour $Htime = @HOUR $Mtime = @MIN $Stime = @SEC $RCL = 0 ;---------------- $MaxScore = 25 ; configurable ;---------------- ;-----------------------NEW--------------------------- $count1 = $MaxScore*5 $StartTicks = _TimeToTicks(@HOUR,@MIN,@SEC) $EndTicks = $StartTicks + $count1 * 60 * 1000 _TicksToTime($EndTicks,$Hour,$Min,$Sec) $tid = $Hour&":"&$Min&":"&$Sec $split = StringSplit($tid,":") ;------------------------------------------------------ While 1 $1sec1 = @SEC $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch $1sec2 = @SEC If $1sec2 > $1sec1 Then ; Do stuff each second to save cpu power and stop flickering _Clock() ; just updates the clock _5minutespass() ; Gives a score every 5 minutes. _LeftFull() EndIf WEnd Func _Clock () $Htime = @HOUR $Mtime = @MIN $Stime = @SEC EndFunc Func _5minutespass () $5min = @MIN $5sec = @SEC If $5min = 00 or $5min = 05 or $5min = 10 or $5min = 15 or $5min = 20 or $5min = 25 or $5min = 30 or $5min = 35 or $5min = 40 or $5min = 45 or $5min = 50 or $5min = 55 Then If $5sec = 01 Then $RCL = $RCL + 1 GUICtrlSetData($Label2,$RCL&"/"&$MaxScore) _MaxRat() EndIf EndIf EndFunc Func _MaxRat() ; tells when meter is full If $RCL = $MaxScore Then MsgBox(0,"Full!","The meter is full.") EndIf EndFunc ;---------------------------NEW----------------------------- Func _LeftFull() $hdiff = _DateDiff('h',@HOUR,$split[1]) $mdiff = _DateDiff('n',@MIN,$split[2]) $sdiff = _DateDiff('s',@SEC,$split[3]) GUICtrlSetData($Label3,$hdiff&":"&$mdiff&":"&$sdiff) EndFunc ;------------------------------------------------------------- I've marked the new parts in the script. A little example would probably help me allot, sometimes I learn better from the wrong end. I'll continue trying, man am I gonna feel proud when I get this to work? Thanks again for the support. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 24, 2011 Moderators Share Posted August 24, 2011 ArkiePazi,I would do something like this: expandcollapse popup#include <GUIConstantsEx.au3> #Include <Date.au3> ;---------------- Global $iMaxScore = 25 ; configurable ;---------------- Global $fStarted = False Global $iRCL = 0 Global $sEndTime $hForm1 = GUICreate("Form1", 117, 87, 310, 266) $hLabel_1 = GUICtrlCreateLabel("Score:", 16, 16, 36, 17) $hLabel_2 = GUICtrlCreateLabel("0/" & $iMaxScore, 64, 16, 36, 17) ; Score/max $hLabel_3 = GUICtrlCreateLabel("", 32, 48, 52, 17) ; Time left until full GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch ; Here we check if the whole process has started If Not $fStarted Then ; If not than we wait for a 00, 05, etc If Not Mod(@SEC, 5) Then ; Yo will need to use @MIN here <<<<<<<<<<<<<<<<<< ; We set the flag to show we are underway $fStarted = True ; This function will run to add a score after the required delay AdlibRegister("_Add_Score", 3000) ; You will need to adjust the 3000 to give the correct delay in millsecs <<<<<<<<<< ; We calculate the time that the process will end $sEndTime = _DateAdd("s", 3 * $iMaxScore, _NowCalc()) ; You will need to adjust the 3 to give the correct delay in secs <<<<<<<<<<<< ; And we run this function every second the reset the countdown AdlibRegister("_Set_Timer", 1000) EndIf EndIf WEnd Func _Add_Score() ; Increase the count and reset the count label $iRCL += 1 GUICtrlSetData($hLabel_2, $iRCL & "/" & $iMaxScore) ; If the process is ended we stop the automatic calling of the functions If $iRCL = $iMaxScore Then AdlibUnRegister("_Add_Score") AdlibUnRegister("_Set_Timer") ; And we set the countdown timer to zero GUICtrlSetData($hLabel_3, "00:00:00") EndIf EndFunc Func _Set_Timer() ; Get the current time in a useable format $sNow = _NowCalc() ; Now get the hours, mons and secs to run to the calculated end time $iHours = StringFormat("%02i", _DateDiff("h", $sNow, $sEndTime)) $iMins = StringFormat("%02i", _DateDiff("n", $sNow, $sEndTime) - $iHours * 60) $iSecs = StringFormat("%02i", _DateDiff("s", $sNow, $sEndTime) - ($iHours * 3600) - ($iMins * 60)) ; And show it GUICtrlSetData($hLabel_3, $iHours & ":" & $iMins & ":" & $iSecs) EndFuncAt the moment it runs the _Add_Score function every 3 secs (I was not going to wait 25 * 5 minutes for each test! ) but I have shown you where you need to adjust the code - look for the <<<<<<< lines. I hope the comments are clear enough for you to follow the logic, but please ask if not. 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...
ArkiePazi Posted August 24, 2011 Author Share Posted August 24, 2011 Yes thank you, the comments were very clear. I will try to implement this in to my program now. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 24, 2011 Moderators Share Posted August 24, 2011 ArkiePazi, You know where I am if you run into difficulties. 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