Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Help or advise needed on multi-timers issue!

$
0
0

hi there!

 

beeing a bit green on autoit, not knowing all the ways arround, i've been trying to bluid a script that provides 2 timers (count-down) BUT having a bit of a problem... i want them to be able to count at the same time...

 

got here so far:

AutoIt         
  1. #include <GUIConstants.au3>
  2. GUICreate("Temporizadores", 150, 150, 438, 156)
  3. $LabelTotal = GUICtrlCreateLabel("00:00", 8, 5, 40, 20)
  4. $Button = GUICtrlCreateButton("Começar", 100, 0, 50, 20) ;  "text", left, top, width, height
  5. $Button1 = GUICtrlCreateButton("Iniciar", 40, 26, 40, 20)
  6. $Label1 = GUICtrlCreateLabel("0:06", 10, 30, 30, 17)
  7. $tempo1 = 6 ; segundos
  8. $Button2 = GUICtrlCreateButton("Iniciar", 40, 46, 40, 20)
  9. $Label2 = GUICtrlCreateLabel("0:06", 10, 50, 30, 17)
  10. $tempo2 = 5 ; segundos
  11.  
  12.  
  13. $time=TimerInit()
  14.     $msg = GUIGetMsg()
  15.     $Total = TimerDiff ($time)
  16.     GUICtrlSetData ($LabelTotal, $Total)
  17.     Select
  18.         Case $msg = $GUI_EVENT_CLOSE
  19.             Exit
  20.  
  21.         Case $msg = $Button1
  22.             contar1()
  23.             $time=TimerInit()
  24.         Case $msg = $Button2
  25.             contar2()
  26.             $time=TimerInit()
  27.  
  28.     EndSelect
  29.  
  30. func contar1()
  31.  
  32.         While 1
  33.             $new = TimerDiff ($time)
  34.             If ($tempo1*1000)-$new <= 0 Then
  35.                 GUICtrlSetData ($Label1, "0:06")
  36.                 ExitLoop
  37.             EndIf
  38.             $new = ($tempo1*1000)-$new
  39.             $seconds = Round ($new/1000)
  40.             $newMin = Floor ($seconds/60)
  41.             $newSec = Mod ($seconds, 60)
  42.             If $newSec < 10 Then $newSec = "0"&$newSec
  43.             GUICtrlSetData ($Label1, $newMin&":"&$newSec)
  44.             Sleep(400)
  45.         Wend
  46. func contar2()
  47.  
  48.         While 1
  49.             $new = TimerDiff ($time)
  50.             If ($tempo1*1000)-$new <= 0 Then
  51.                 GUICtrlSetData ($Label2, "0:06")
  52.                 ExitLoop
  53.             EndIf
  54.             $new = ($tempo1*1000)-$new
  55.             $seconds = Round ($new/1000)
  56.             $newMin = Floor ($seconds/60)
  57.             $newSec = Mod ($seconds, 60)
  58.             If $newSec < 10 Then $newSec = "0"&$newSec
  59.             GUICtrlSetData ($Label2, $newMin&":"&$newSec)
  60.             Sleep(400)
  61.         Wend
  62.  

any ideas/toughts that may point me in the right direction?

 

thank you!


Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>