AutoIT Inserire un timer nella GUI

Stato
Discussione chiusa ad ulteriori risposte.

0xEHz

Utente Palladium
2 Luglio 2009
4,294
230
1,319
1,856
Molto semplice (per voi), ma non per me.

Ho questa gui:

Codice:
#include <ButtonConstants.au3>#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Ciao Bot v0.2 [BETA]", 590, 215, 1298, 3, -1, $WS_EX_TOPMOST)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 297, 200)
GUICtrlSetData(-1, "Edit1")
$Group1 = GUICtrlCreateGroup("Variabili", 328, 8, 249, 200)
$Label1 = GUICtrlCreateLabel("firstX:", 344, 32, 30, 17)
$Label2 = GUICtrlCreateLabel("firstY:", 344, 56, 30, 17)
$Label3 = GUICtrlCreateLabel("secondX:", 344, 80, 49, 17)
$Label4 = GUICtrlCreateLabel("secondY:", 344, 104, 49, 17)
$Label5 = GUICtrlCreateLabel("counter:", 344, 128, 43, 17)
$Label6 = GUICtrlCreateLabel("fX:", 472, 32, 17, 17)
$Label7 = GUICtrlCreateLabel("fY:", 472, 56, 17, 17)
$Label8 = GUICtrlCreateLabel("sX:", 472, 80, 19, 17)
$Label9 = GUICtrlCreateLabel("sY :", 472, 104, 22, 17)
$Label10 = GUICtrlCreateLabel("Quality:", 472, 128, 39, 17)
$Label11 = GUICtrlCreateLabel("0", 384, 32, 42, 17)
$Label12 = GUICtrlCreateLabel("0", 384, 56, 42, 17)
$Label13 = GUICtrlCreateLabel("0", 400, 80, 42, 17)
$Label14 = GUICtrlCreateLabel("0", 400, 104, 42, 17)
$Label15 = GUICtrlCreateLabel("0", 392, 128, 42, 17)
$Label16 = GUICtrlCreateLabel("0", 496, 32, 42, 17)
$Label17 = GUICtrlCreateLabel("0", 496, 56, 42, 17)
$Label18 = GUICtrlCreateLabel("0", 496, 80, 42, 17)
$Label19 = GUICtrlCreateLabel("0", 496, 104, 42, 17)
$Label20 = GUICtrlCreateLabel("n/d", 520, 128, 42, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Io vorrei inserire un timer che conti alla rovescia da un valore dato da me ($sleepTime).

Mi serve per mostrare quanto il bot resta fermo ogni volta, e quindi dire tra quanto riprenderà.

Ad esempio:


Codice:
$sleepTime = Random(30000,150000,1) ; Tempo di attesa generato casualmente 
sleep($sleepTime)

Qualcuno saprebbe aiutarmi? :)
 
[MENTION=50663]EHz_[/MENTION]
In pratica utilizzi un ciclo for per eseguire l'operazione di sleep per "SleepTime/1000" (perché per la funzione sleep ci vogliono ovviamente i millesimi) volte. Se vuoi provare a fare tu, ecco una pagina che ti potrà essere utile. In caso contrario, il code è nello spoiler.
Codice:
$sleepTime = Random(30000,150000,1) ; Tempo di attesa generato casualmente
for $i = ($sleepTime/1000) to 0 Step -1
   Sleep(1000)
   ;Qui modifichi il valore del label assegnato al timer
   Next
 
  • Mi piace
Reazioni: 0xEHz
Grazie, avevo pensato a tutto fuorché un ciclo for :asd:
provo!

- - - Updated - - -

Ok, [MENTION=200092]Because[/MENTION], con il tuo consiglio ho fatto questo*

Codice:
Func wait($sec)
   _GUICtrlEdit_AppendText($Edit1, @CRLF & @CRLF & "Attendo " & $sec & " secondi" & @CRLF)
   GUICtrlSetState($Label23, $GUI_SHOW)
   GUICtrlSetState($Label24, $GUI_SHOW)
   for $i = $sec to 0 step -1
	  GUICtrlSetData($Label24, $i)
	  sleep(1000)
   Next
   GUICtrlSetState($Label23, $GUI_HIDE)
   GUICtrlSetState($Label24, $GUI_HIDE)
EndFunc

In pratica invece di sleep(millisecondi) uso wait(secondi). La funzione mi mostra il timer, lo aggiorna e lo nasconde una volta finito, in più scrive nella tab dei Log!
Chiudo e grazie ancora! ;)
 
Stato
Discussione chiusa ad ulteriori risposte.