boltc Posted December 15, 2006 Share Posted December 15, 2006 (edited) hello,,im making some countdowntimers but it wont start.. need your helphere is me script:expandcollapse popup#include "timerlib.au3" #include <GUIConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Timer", 239, 146, 193, 115) $Input1 = GUICtrlCreateInput("", 16, 8, 57, 21) $Start = GUICtrlCreateButton("Start", 104, 8, 65, 25, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $tijd ClockInit(1000, "klok1", False) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Start $tijd = guictrlread($Input1) ClockStart(1) Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd While 1 Sleep(10) WEnd Func klok1($timerno) $tijd = $tijd - 1 GUICtrlSetData($Input1, $tijd) if $tijd = 0 Then Clockstop(1) MsgBox(0, "", "done.") EndIf EndFuncand the timerlib.au3:expandcollapse popup#include-once #region Header #comments-start Title: Timer Lib UDF Library for AutoIt3 Filename: TimerLib.au3 Description: A collection of UDF's that assist in defining several timers with function callbacks. Author: J. DERN (JD) Version: 01.00 Last Update: 27.11.06 Requirements: AutoIt v3.2 +, Developed/Tested on WindowsXP Pro Service Pack 2 Notes: This code is optimized even with only one timer, it will takes less CPU if timer have a common divider #comments-end #endregion Header #region Global Variables and Constants Global $ClockArray[2][3]=[[0,0,0]] Global $ClockCounter=0 ;------------------------------------------------------------------------------------------------------ ;- D E M O N S T R A T I O N ;------------------------------------------------------------------------------------------------------ ;ClockInit(1000, "A", False) ;ClockAdd (2000, "B", False) ;ClockAdd (500, "C", True) ;ClockStartAll() ;While 1 ; Sleep(10) ;WEnd ;Func A($timerno) ; ToolTip("A", 0, 0, "Time") ;EndFunc ;Func B($timerno) ; ToolTip("B", 50, 50, "Time") ;EndFunc ;Func C($timerno) ; ToolTip("C", 100, 100, "Time") ;EndFunc ;Exit ;------------------------------------------------------------------------------------------------------ ;- T I M E R L I B R A R Y ;------------------------------------------------------------------------------------------------------ ;=============================================================================== ; Description: Initialize clock and add first timer. ; Parameter(s): $frequence - Call frequence in microseconds. ; $function - Function to call each $frequence microseconds (timer number is passed in argument) ; $start - Optional - True/False. True = start immediatly the timer ; Requirement(s): AdlibEnable() or AdlibDisable() not used outside TimerLib ; Return Value(s): The number of added timer ; Author(s): Jerome DERN (jdern "at" free "dot" fr) ; Note(s): Multiple calls to this function will resets previously defined timers ;=============================================================================== Func ClockInit($frequence, $function, $start=True) ; Initialize tables $ClockArray[0][0] = 1 ; Number of timers $ClockArray[0][1] = $frequence; Actual frequency $ClockArray[0][2] = 1 ; Max value of counter ; Initialize first timer $ClockArray[1][0] = 1 ; Number of Tick $ClockArray[1][1] = $function; Function to call $ClockArray[1][2] = True; Activated If $start Then ClockStartAll() Return 1 EndFunc ;=============================================================================== ; Description: Add a new timer. ; Parameter(s): $frequence - Call frequence in microseconds. ; $function - Function to call each $frequence microseconds ; $start - Optional - True/False. True = start immediatly the timer ; Requirement(s): ClockInit() first called, AdlibEnable() or AdlibDisable() not used outside TimerLib ; Return Value(s): The numer of added timer ; Author(s): Jerome DERN (jdern "at" free "dot" fr) ; Note(s): ;=============================================================================== Func ClockAdd($frequence, $function, $start=True) ; ClockInit already called? If not initialize the first timer If $ClockArray[0][0] <= 0 Then Return ClockInit($frequence, $function, $start) AdlibDisable() ; Disable timer ReDim $ClockArray[$ClockArray[0][0]+2][3]; Redim the timer table $nb = $ClockArray[0][0] ; Get number of timers ; Convert nb of timeslot to timeslot duration $time = $ClockArray[0][1] ; Get actual timeslot duration For $i=1 to $nb $ClockArray[$i][0] *= $time ; = Nbslot*slotduration (timeslot duration) Next ; Add new timer $nb += 1 $ClockArray[$nb][0] = $frequence ; Number of clock tick to activate it $ClockArray[$nb][1] = $function ; Function to be called $ClockArray[$nb][2] = True ; Activated ; Get maximum timeslot and common maximum divisor $time = $ClockArray[1][0] ; Get first timeslot duration $max = $time For $i=1 to $nb If $ClockArray[$i][0] > $max Then $max = $ClockArray[$i][0]; Max? $time = ClockPGCD($time, $ClockArray[$i][0]); Find greater common divisor Next ; Convert back timeslot durations to number of timeslot For $i=1 to $nb $ClockArray[$i][0] /= $time ; Nb of clock tick Next ; Update general informations $ClockArray[0][0] = $nb ; New number of timers $ClockArray[0][1] = $time ; Actual frequency $ClockArray[0][2] = $max/$time; Max value of counter If $start Then ClockStartAll() Return $nb EndFunc ;=============================================================================== ; Description: Start a timer given by its number ; Parameter(s): $number - The timer number to start, or callback function name. ; Requirement(s): ClockInit() first called, AdlibEnable() or AdlibDisable() not used outside TimerLib ; Return Value(s): 1 if OK ; -1 if no timer found ; -2 if already started ; Author(s): Jerome DERN (jdern "at" free "dot" fr) ; Note(s): $number is returned by ClockInit() or ClockAdd() services. Stop timer with ClockStop() ;=============================================================================== Func ClockStart($number) If Not IsNumber($number) And IsString($number) Then $name = $number For $i=1 to $ClockArray[0][0] If $ClockArray[$i][1] = $number Then $number = $i ExitLoop EndIf Next EndIf If $ClockArray[0][0] < $number Then Return -1 If $ClockArray[$number][2] = True Then Return -2 $ClockArray[$number][2] = True Return 1 EndFunc ;=============================================================================== ; Description: Stop a timer given by its number ; Parameter(s): $number - The timer number to stop, or callback function name. ; Requirement(s): ClockInit() first called, AdlibEnable() or AdlibDisable() not used outside TimerLib ; Return Value(s): 1= 0K ; -1 If no timer found ; -2 If timer already stopped ; Author(s): Jerome DERN (jdern "at" free "dot" fr) ; Note(s): $number is returned by ClockInit() or ClockAdd() services. Start again with ClockStart() ;=============================================================================== Func ClockStop($number) If Not IsNumber($number) And IsString($number) Then $name = $number For $i=1 to $ClockArray[0][0] If $ClockArray[$i][1] = $number Then $number = $i ExitLoop EndIf Next EndIf If $ClockArray[0][0] < $number Then Return -1 If $ClockArray[$number][2] = False Then Return -2 $ClockArray[$number][2] = False Return 1 EndFunc ;=============================================================================== ; Description: Stop all defined timers ; Parameter(s): $number - The timer number to stop. ; Requirement(s): ClockInit() first called, AdlibEnable() or AdlibDisable() not used outside TimerLib ; Return Value(s): None ; Author(s): Jerome DERN (jdern "at" free "dot" fr) ; Note(s): ClockInit() already called. Start all timers again with ClockStartAll() ;=============================================================================== Func ClockStopAll() AdlibDisable() EndFunc ;=============================================================================== ; Description: Start all defined timers ; Parameter(s): $number - The timer number to stop. ; Requirement(s): ClockInit() first called, AdlibEnable() or AdlibDisable() not used outside TimerLib ; Return Value(s): 1 if OK, -1 if ClockInit() not called or no timer found ; Author(s): Jerome DERN (jdern "at" free "dot" fr) ; Note(s): ClockInit() already called. Stop all services by ClockStopAll() ;=============================================================================== Func ClockStartAll() If $ClockArray[0][0] < 1 Then Return -1 If $ClockArray[0][0] = 1 Then AdlibEnable($ClockArray[1][1], $ClockArray[0][1]) Else AdlibEnable("ClockCallback", $ClockArray[0][1]) EndIf Return 1 EndFunc ;=============================================================================== ; Description: Debug: print in tooltips all timers and their status ; Parameter(s): none ; Requirement(s): ClockInit() first called, AdlibEnable() or AdlibDisable() not used outside TimerLib ; Return Value(s): number of timers defined ; Author(s): Jerome DERN (jdern "at" free "dot" fr) ; Note(s): For debugging purposed no use in production code ;=============================================================================== Func ClockDebug() $info = $ClockArray[0][0] & " Clock defined" & @CRLF For $i=1 to $ClockArray[0][0] $period = $ClockArray[$i][0] * $ClockArray[0][1] $h = Int($period / (60*60000)) $period -= $h*60*60000 $m = Int($period/60000) $period -= $m*60000 $s = Int($period/1000) $ms = $period - $s*1000 $period = "" if $h >0 then $period = $period & $h & "h " if $m >0 then $period = $period & $m & "m " if $s >0 then $period = $period & $s &"s " if $ms >0 then $period = $period & $ms & "ms " $info = $info & " Clock " & $i & " status is " & $ClockArray[$i][2] & " at " & $period & "Callback is " & $ClockArray[$i][1] & @CRLF Next ToolTip($info, 0, 0, "ClockLib debug") Return $ClockArray[0][0] EndFunc ;------------------------------------------------------------------------------------------------------ ;- U T I L I T A R Y F U N C T I O N S N O T E X P O R T E D ;------------------------------------------------------------------------------------------------------ ; The timer adlib general callback Func ClockCallback() $ClockCounter += 1 For $i=1 to $ClockArray[0][0] If Not $ClockArray[$i][2] Then ContinueLoop If $ClockArray[$i][0]=1 Or Mod($ClockCounter, $ClockArray[$i][0]) = 0 Then Call($ClockArray[$i][1], $i) Next If $ClockCounter >= $ClockArray[0][2] Then $ClockCounter = 0 EndFunc ; Compute higher common divisor of two numbers Func ClockPGCD($a, $b) If $b=0 Then $ClockPGCD=$a Else $c = $a/$b $c = Round(($c-int($c))*$b, 0) $ClockPGCD = ClockPGCD($b, $c) EndIf Return $ClockPGCD EndFuncend here is my old script.. this works, but i want to start more counters...:expandcollapse popup#include "timerlib.au3" #include <GUIConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Timer", 239, 146, 193, 115) $Input1 = GUICtrlCreateInput("", 16, 8, 57, 21) $Start = GUICtrlCreateButton("Start", 104, 8, 65, 25, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $tijd While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Start call(_startklok1()) Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd While 1 Sleep(10) WEnd func _startklok1() $tijd = guictrlread($Input1) ClockInit(1000, "klok1", True) EndFunc Func klok1($timerno) $tijd = $tijd - 1 GUICtrlSetData($Input1, $tijd) if $tijd = 0 Then ClockStopall() MsgBox(0, "", "done..") EndIf EndFunccan you guys help me? thx Edited December 15, 2006 by boltc Link to comment Share on other sites More sharing options...
boltc Posted December 16, 2006 Author Share Posted December 16, 2006 still nobody can help me? Link to comment Share on other sites More sharing options...
Developers Jos Posted December 16, 2006 Developers Share Posted December 16, 2006 I am not familiar with the TimerLib.au3 and made several changes to get it to work... See if this helps you: expandcollapse popup;#include "timerlib.au3" #include <GUIConstants.au3> Global $ClockArray[2][3]=[[0,0,0]] Global $ClockCounter=0 #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Timer", 239, 146, 193, 115) $Input1 = GUICtrlCreateInput("", 16, 8, 57, 21) $Start1 = GUICtrlCreateButton("Start", 104, 8, 65, 25, 0) $Input2 = GUICtrlCreateInput("", 16, 38, 57, 21) $Start2 = GUICtrlCreateButton("Start", 104, 38, 65, 25, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $tijd ClockInit(1000, "klok1", False) ClockAdd(2000, "klok2", False) ClockStartAll() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Start1 ; ClockStart("klok1") Case $Start2 ; ClockStart("klok2") Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func klok1($timerno) $tijd = GUICtrlRead($Input1) GUICtrlSetData($Input1, $tijd-1) if $tijd = 0 Then ClockStopall() MsgBox(0, "", "done..") EndIf EndFunc Func klok2($timerno) $tijd = GUICtrlRead($Input2) GUICtrlSetData($Input2, $tijd-1) if $tijd = 0 Then ClockStopall() MsgBox(0, "", "done..") EndIf EndFunc #region Header #comments-start Title: Timer Lib UDF Library for AutoIt3 Filename: TimerLib.au3 Description: A collection of UDF's that assist in defining several timers with function callbacks. Author: J. DERN (JD) Version: 01.00 Last Update: 27.11.06 Requirements: AutoIt v3.2 +, Developed/Tested on WindowsXP Pro Service Pack 2 Notes: This code is optimized even with only one timer, it will takes less CPU if timer have a common divider #comments-end #endregion Header ;------------------------------------------------------------------------------------------------------ ;- D E M O N S T R A T I O N ;------------------------------------------------------------------------------------------------------ ;ClockInit(1000, "A", False) ;ClockAdd (2000, "B", False) ;ClockAdd (500, "C", True) ;ClockStartAll() ;While 1 ; Sleep(10) ;WEnd ;Func A($timerno) ; ToolTip("A", 0, 0, "Time") ;EndFunc ;Func B($timerno) ; ToolTip("B", 50, 50, "Time") ;EndFunc ;Func C($timerno) ; ToolTip("C", 100, 100, "Time") ;EndFunc ;Exit ;------------------------------------------------------------------------------------------------------ ;- T I M E R L I B R A R Y ;------------------------------------------------------------------------------------------------------ ;=============================================================================== ; Description: Initialize clock and add first timer. ; Parameter(s): $frequence - Call frequence in microseconds. ; $function - Function to call each $frequence microseconds (timer number is passed in argument) ; $start - Optional - True/False. True = start immediatly the timer ; Requirement(s): AdlibEnable() or AdlibDisable() not used outside TimerLib ; Return Value(s): The number of added timer ; Author(s): Jerome DERN (jdern "at" free "dot" fr) ; Note(s): Multiple calls to this function will resets previously defined timers ;=============================================================================== Func ClockInit($frequence, $function, $start=True) ; Initialize tables $ClockArray[0][0] = 1 ; Number of timers $ClockArray[0][1] = $frequence; Actual frequency $ClockArray[0][2] = 1 ; Max value of counter ; Initialize first timer $ClockArray[1][0] = 1 ; Number of Tick $ClockArray[1][1] = $function; Function to call $ClockArray[1][2] = False; Activated If $start Then ClockStartAll() Return 1 EndFunc ;=============================================================================== ; Description: Add a new timer. ; Parameter(s): $frequence - Call frequence in microseconds. ; $function - Function to call each $frequence microseconds ; $start - Optional - True/False. True = start immediatly the timer ; Requirement(s): ClockInit() first called, AdlibEnable() or AdlibDisable() not used outside TimerLib ; Return Value(s): The numer of added timer ; Author(s): Jerome DERN (jdern "at" free "dot" fr) ; Note(s): ;=============================================================================== Func ClockAdd($frequence, $function, $start=True) ; ClockInit already called? If not initialize the first timer If $ClockArray[0][0] <= 0 Then Return ClockInit($frequence, $function, $start) AdlibDisable() ; Disable timer ReDim $ClockArray[$ClockArray[0][0]+2][3]; Redim the timer table $nb = $ClockArray[0][0] ; Get number of timers ; Convert nb of timeslot to timeslot duration $time = $ClockArray[0][1] ; Get actual timeslot duration For $i=1 to $nb $ClockArray[$i][0] *= $time ; = Nbslot*slotduration (timeslot duration) Next ; Add new timer $nb += 1 $ClockArray[$nb][0] = $frequence ; Number of clock tick to activate it $ClockArray[$nb][1] = $function ; Function to be called $ClockArray[$nb][2] = False ; Activated ; Get maximum timeslot and common maximum divisor $time = $ClockArray[1][0] ; Get first timeslot duration $max = $time For $i=1 to $nb If $ClockArray[$i][0] > $max Then $max = $ClockArray[$i][0]; Max? $time = ClockPGCD($time, $ClockArray[$i][0]); Find greater common divisor Next ; Convert back timeslot durations to number of timeslot For $i=1 to $nb $ClockArray[$i][0] /= $time ; Nb of clock tick Next ; Update general informations $ClockArray[0][0] = $nb ; New number of timers $ClockArray[0][1] = $time ; Actual frequency $ClockArray[0][2] = $max/$time; Max value of counter If $start Then ClockStartAll() Return $nb EndFunc ;=============================================================================== ; Description: Start a timer given by its number ; Parameter(s): $number - The timer number to start, or callback function name. ; Requirement(s): ClockInit() first called, AdlibEnable() or AdlibDisable() not used outside TimerLib ; Return Value(s): 1 if OK ; -1 if no timer found ; -2 if already started ; Author(s): Jerome DERN (jdern "at" free "dot" fr) ; Note(s): $number is returned by ClockInit() or ClockAdd() services. Stop timer with ClockStop() ;=============================================================================== Func ClockStart($number) If Not IsNumber($number) And IsString($number) Then $name = $number For $i=1 to $ClockArray[0][0] If $ClockArray[$i][1] = $number Then $number = $i ExitLoop EndIf Next EndIf If $ClockArray[0][0] < $number Then Return -1 If $ClockArray[$number][2] = True Then Return -2 $ClockArray[$number][2] = True Return 1 EndFunc ;=============================================================================== ; Description: Stop a timer given by its number ; Parameter(s): $number - The timer number to stop, or callback function name. ; Requirement(s): ClockInit() first called, AdlibEnable() or AdlibDisable() not used outside TimerLib ; Return Value(s): 1= 0K ; -1 If no timer found ; -2 If timer already stopped ; Author(s): Jerome DERN (jdern "at" free "dot" fr) ; Note(s): $number is returned by ClockInit() or ClockAdd() services. Start again with ClockStart() ;=============================================================================== Func ClockStop($number) If Not IsNumber($number) And IsString($number) Then $name = $number For $i=1 to $ClockArray[0][0] If $ClockArray[$i][1] = $number Then $number = $i ExitLoop EndIf Next EndIf If $ClockArray[0][0] < $number Then Return -1 If $ClockArray[$number][2] = False Then Return -2 $ClockArray[$number][2] = False Return 1 EndFunc ;=============================================================================== ; Description: Stop all defined timers ; Parameter(s): $number - The timer number to stop. ; Requirement(s): ClockInit() first called, AdlibEnable() or AdlibDisable() not used outside TimerLib ; Return Value(s): None ; Author(s): Jerome DERN (jdern "at" free "dot" fr) ; Note(s): ClockInit() already called. Start all timers again with ClockStartAll() ;=============================================================================== Func ClockStopAll() AdlibDisable() EndFunc ;=============================================================================== ; Description: Start all defined timers ; Parameter(s): $number - The timer number to stop. ; Requirement(s): ClockInit() first called, AdlibEnable() or AdlibDisable() not used outside TimerLib ; Return Value(s): 1 if OK, -1 if ClockInit() not called or no timer found ; Author(s): Jerome DERN (jdern "at" free "dot" fr) ; Note(s): ClockInit() already called. Stop all services by ClockStopAll() ;=============================================================================== Func ClockStartAll() If $ClockArray[0][0] < 1 Then Return -1 If $ClockArray[0][0] = 1 Then AdlibEnable($ClockArray[1][1], $ClockArray[0][1]) Else AdlibEnable("ClockCallback", $ClockArray[0][1]) EndIf Return 1 EndFunc ;=============================================================================== ; Description: Debug: print in tooltips all timers and their status ; Parameter(s): none ; Requirement(s): ClockInit() first called, AdlibEnable() or AdlibDisable() not used outside TimerLib ; Return Value(s): number of timers defined ; Author(s): Jerome DERN (jdern "at" free "dot" fr) ; Note(s): For debugging purposed no use in production code ;=============================================================================== Func ClockDebug() $info = $ClockArray[0][0] & " Clock defined" & @CRLF For $i=1 to $ClockArray[0][0] $period = $ClockArray[$i][0] * $ClockArray[0][1] $h = Int($period / (60*60000)) $period -= $h*60*60000 $m = Int($period/60000) $period -= $m*60000 $s = Int($period/1000) $ms = $period - $s*1000 $period = "" if $h >0 then $period = $period & $h & "h " if $m >0 then $period = $period & $m & "m " if $s >0 then $period = $period & $s &"s " if $ms >0 then $period = $period & $ms & "ms " $info = $info & " Clock " & $i & " status is " & $ClockArray[$i][2] & " at " & $period & "Callback is " & $ClockArray[$i][1] & @CRLF Next ToolTip($info, 0, 0, "ClockLib debug") Return $ClockArray[0][0] EndFunc ;------------------------------------------------------------------------------------------------------ ;- U T I L I T A R Y F U N C T I O N S N O T E X P O R T E D ;------------------------------------------------------------------------------------------------------ ; The timer adlib general callback Func ClockCallback() $ClockCounter += 1 For $i=1 to $ClockArray[0][0] If Not $ClockArray[$i][2] Then ContinueLoop If $ClockArray[$i][0]=1 Or Mod($ClockCounter, $ClockArray[$i][0]) = 0 Then Call($ClockArray[$i][1], $i) Next If $ClockCounter >= $ClockArray[0][2] Then $ClockCounter = 0 EndFunc ; Compute higher common divisor of two numbers Func ClockPGCD($a, $B) If $b=0 Then $ClockPGCD=$a Else $c = $a/$b $c = Round(($c-int($c))*$b, 0) $ClockPGCD = ClockPGCD($b, $c) EndIf Return $ClockPGCD EndFunc SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
boltc Posted December 16, 2006 Author Share Posted December 16, 2006 yes this works, but if the first clock stops, then the 2e clock also stops:S Link to comment Share on other sites More sharing options...
boltc Posted December 16, 2006 Author Share Posted December 16, 2006 haha thankyou,, have it working now... just changed this: Func klok1($timerno) $tijd = GUICtrlRead($Input1) GUICtrlSetData($Input1, $tijd-1) if $tijd = 0 Then ClockStop(1) MsgBox(0, "", "done..") EndIf EndFunc Func klok2($timerno) $tijd = GUICtrlRead($Input2) GUICtrlSetData($Input2, $tijd-1) if $tijd = 0 Then ClockStop(2) MsgBox(0, "", "done..") EndIf EndFunc 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