Sign in to follow this  
Followers 0
tomagucci

help with timer

12 posts in this topic

#1 ·  Posted (edited)

So heres the deal, I have a timer that runs and exits at the beginning of my script, when it exits a bunch of specified tasks run then the code is repeated, when it starts over, I have another timer there, but for some reason the second timer does not get the defined time and stays at "00:00:00", any help would be greatly appreciated. heres the first timer code

#include <GUIConstants.au3>
#include <Date.au3>

Dim $SleepTime = 43000
Dim $SleepTime2 = 4300
Global $timer = TimerInit()
Global $timer2 = TimerInit()
Global $Secs, $Mins, $Hour, $Time, $Time2, $Secs2, $Mins2, $Hour2

Func SleepTimer()  <--- this one works perfectly
        AdlibEnable("Timer", 50)
        create()
        While 1
        $msg = GUIGetMsg()
        Select
        Case $msg = $GUI_EVENT_CLOSE
            GuiDelete ($sleeptimer)
            Return
        EndSelect 
        Wend
        Timer()
        sleep ($SleepTime)
EndFunc

func Create()
    Global $sleeptimer = GUICreate("Timer for Sleep",240, 50)
    GUICtrlCreateLabel("00:00:00", 10,10)
    GUISetState()
EndFunc


Func Timer()
        
    _TicksToTime($SleepTime-Int(TimerDiff($timer)), $Hour, $Mins, $Secs )
    Local $sTime = $Time; save current time to be able to test and avoid flicker..
    $Time = StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs)
    If $sTime <> $Time Then ControlSetText("Timer", "", "Static1", $Time)
    If $sTime = "00:00:00" Then
        GUIDelete ($sleeptimer)
    EndIf
EndFunc;Timer 

here is the second one, it just starts and stops at "00:00:00", the if then code actually closes it right away because it doesnt change from "00:00:00"

Func SleepTimer2()
        AdlibEnable("Timer2", 50)
        create2()
        While 1
        $msg2 = GUIGetMsg()
        Select
        Case $msg2 = $GUI_EVENT_CLOSE
            GuiDelete ($sleeptimer2)
            Return
        EndSelect
        Wend
        Timer2()
        sleep ($SleepTime2)
EndFunc

func Create2()
    Global $SleepTimer2 = GUICreate("Timer",240, 50)
    GUICtrlCreateLabel("00:00:00", 10,10)
    GUISetState()
EndFunc


Func Timer2()
        
    _TicksToTime($SleepTime2-Int(TimerDiff($timer2)), $Hour2, $Mins2, $Secs2)
    Local $sTime2 = $Time2; save current time to be able to test and avoid flicker..
    $Time2 = StringFormat("%02i:%02i:%02i", $Hour2, $Mins2, $Secs2)
    If $sTime2 <> $Time2 Then ControlSetText("Timer", "", "Static1", $Time2)
;If $sTime2 = "00:00:00" Then
;GUIDelete ($SleepTimer2)
;EndIf
EndFunc;==>Timer


            
                


    Edited  by tomagucci
    
    

            
        

        
            
                

    
        
            
        
    


            
        

        
            
                
                
                
            
            
                
            
        
        
    

    
        
            Share this post
            
Link to post
            
            
            

            
                Share on other sites
                

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    

            
        
    


    

                    
                        





(adsbygoogle = window.adsbygoogle || []).push({});




                    
                
                    
                    
                    






    
    
        
Aceguy   

    
        
    
             0
    
        
    

        
            
                YAY ME.....
            
            

            
                

    
        
    

            
            Active Members
            
            
                

    
        
    
             0
    
        
    

                629 posts
                
                

            
        
    
    
        


    

    
        
            
            
                
            
            
        

        
    #2 · 
            Posted 
            
            
            
        
    

    


            
        
            Hope this helps as am example
#include <GUIConstants.au3>
#include <Date.au3>

Global $time

Dim $Label[3]
dim $time[3]

$time[1] =10
$time[2] =4


$Form1 = GUICreate("Form1", 475, 250, 249, 172)
$Label[1] = GUICtrlCreateLabel("Label1", 16, 24, 36, 17)
$Label[2] = GUICtrlCreateLabel("Label2", 24, 64, 36, 17)
GUISetState(@SW_SHOW)

AdlibEnable("time", 1000)


While 1
    
    Sleep(250)
WEnd

Func time()
    
    For $x = 1 To 2
        $time[$x]+=1
        GUICtrlSetData($Label[$x], $time[$x])
    Next
EndFunc   ;==>time

Share this post


Link to post
Share on other sites

and with a reset add

Func time()
    For $x = 1 To 2
        $time[$x]+=1
        GUICtrlSetData($Label[$x], $time[$x])
        ; with a reset
        if $time[2] = 15 then $time[2]=0
    Next
EndFunc   ;==>time

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

but i need a gui created and closed, and then another created and closed. it has to be linearly, do you think that is why its messing up?, If i just put the second into auto it by itself without anything it works, but when it is at the end of the large function, it messes up, is there something that is carried over and not reset? is there something I can do to reset it?

Edited by tomagucci

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

something is messing up even before the sleep($sleeptime2) because its not like the gui is just opened and closed, the script just stops there, script is still running, just nothing is happening. anyone got a clue?

Edited by tomagucci

Share this post


Link to post
Share on other sites

You really should just create the GUIs outside a function/loop then show the one that needs to be called.

$frmGUI1 = GUICreate("GUI 1",-1,-1,-1,-1)
$frmGUI2 = GUICreate("GUI 2",-1,-1,-1,-1)

GUISetState(@SW_SHOW,$frmGUI1)

;do something

GUISetState(@SW_HIDE,$frmGUI1)
GUISetState(@SW_SHOW,$frmGUI2)


;do stuff here
Not a very elegant example but it gets the point across

Share this post


Link to post
Share on other sites

I Like The Following Code But What If I Wanted To Close The Program ?? This Is Not Alowing Me To Close?

#include <GUIConstants.au3>
#include <Date.au3>

Dim $SleepTime = 43000
Dim $SleepTime2 = 4300
Global $timer = TimerInit()
Global $timer2 = TimerInit()
Global $Secs, $Mins, $Hour, $Time, $Time2, $Secs2, $Mins2, $Hour2

Func SleepTimer()  <--- this one works perfectly
        AdlibEnable("Timer", 50)
        create()
        While 1
        $msg = GUIGetMsg()
        Select
        Case $msg = $GUI_EVENT_CLOSE
            GuiDelete ($sleeptimer)
            Return
        EndSelect
        Wend
        Timer()
        sleep ($SleepTime)
EndFunc

func Create()
    Global $sleeptimer = GUICreate("Timer for Sleep",240, 50)
    GUICtrlCreateLabel("00:00:00", 10,10)
    GUISetState()
EndFunc


Func Timer()
        
    _TicksToTime($SleepTime-Int(TimerDiff($timer)), $Hour, $Mins, $Secs )
    Local $sTime = $Time; save current time to be able to test and avoid flicker..
    $Time = StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs)
    If $sTime <> $Time Then ControlSetText("Timer", "", "Static1", $Time)
    If $sTime = "00:00:00" Then
        GUIDelete ($sleeptimer)
    EndIf
EndFunc;Timer

here is the second one, it just starts and stops at "00:00:00", the if then code actually closes it right away because it doesnt change from "00:00:00"

Func SleepTimer2()
        AdlibEnable("Timer2", 50)
        create2()
        While 1
        $msg2 = GUIGetMsg()
        Select
        Case $msg2 = $GUI_EVENT_CLOSE
            GuiDelete ($sleeptimer2)
            Return
        EndSelect
        Wend
        Timer2()
        sleep ($SleepTime2)
EndFunc

func Create2()
    Global $SleepTimer2 = GUICreate("Timer",240, 50)
    GUICtrlCreateLabel("00:00:00", 10,10)
    GUISetState()
EndFunc


Func Timer2()
        
    _TicksToTime($SleepTime2-Int(TimerDiff($timer2)), $Hour2, $Mins2, $Secs2)
    Local $sTime2 = $Time2; save current time to be able to test and avoid flicker..
    $Time2 = StringFormat("%02i:%02i:%02i", $Hour2, $Mins2, $Secs2)
    If $sTime2 <> $Time2 Then ControlSetText("Timer", "", "Static1", $Time2)
;If $sTime2 = "00:00:00" Then
;GUIDelete ($SleepTimer2)
;EndIf
EndFunc;==>Timer[code]

Google Is For Real Men. Yahoo Is For Wimps!

Share this post


Link to post
Share on other sites

i dont want to close it, i just want, if i close the gui to go onto the next function in the main script. I am just having trouble with the second timer.... blah I tried to make 2 at the same time but it doesnt work... the second one still doesnt show up...

Share this post


Link to post
Share on other sites

can anyone help me out with getting the second one to function, or tell me why it doesnt work like it should?

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

blah, now i realize that it isn't even going to the next function in the script, it only goes to the next Function if i close it by clicking the X..... can someone explain why?, see all it is is that I need the script to sleep for a very long time (excess of 3+ more hours) I want there to be something showing the time left for sleep, the thing is though, that I dont want it shown in milliseconds, I want it in 00:00:00 and the only way i know how to get that format is through a GUI, if anyone has a better or different approach I would love to hear it, and there are multiple places where the script will sleep, I need a window to show that sleep time each time.

I just thought of something that might work, but im not exactly sure how to do it, can I just recall $sleeptimer, the first one, and reset it back to 00:00:00 and have another timer() function do another countdown with a different variable. anyone got any ideas?

EDIT:

I just found out what the problem is, okay whether i use two different gui, or the same one, the time for the gui does not get reset back to zero then pick up the new tickstotime, if i close the gui at 43 seconds, when the second one opens it starts from 43 and not from where the variable should start from.

Edited by tomagucci

Share this post


Link to post
Share on other sites

I think the problem is in the _tickstotime fucntion, in that timerdiff calls upon the former number... is there anyway to get around this?

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0