Sign in to follow this  
Followers 0
Moras

How To Repeat Script

4 posts in this topic

I have modified this timer script to do what i want but i cant get it to repeat? i tried using a do...until loop but i couldnt seem to get it to work properly. Am i going about this wrong?

#include <GUIConstants.au3>

#include <Date.au3>

Global $Secs, $Mins, $Hour, $Time, $InitialT, $TargetT

GUICreate("Timer", 200, 100)

$MinIn = GUICtrlCreateInput("00", 70, 10, 30, 20, $ES_NUMBER)

$label = GUICtrlCreateLabel(":", 101, 12)

$SecIn = GUICtrlCreateInput("00", 105, 10, 30, 20, $ES_NUMBER)

$start = GUICtrlCreateButton("Start", 75, 50, 50, 30)

$timeLabel = GUICtrlCreateLabel("00:00:00", 80, 20)

GUICtrlSetState($timeLabel, $GUI_HIDE)

GUISetState(@SW_SHOW)

$started = 0

While 1

;After every loop check if the user clicked something in the GUI window

$msg = GUIGetMsg()

Select

;Check if user clicked on the close button

Case $msg = $GUI_EVENT_CLOSE

;Destroy the GUI including the controls

GUIDelete()

ExitLoop

Case $msg = $start

If GUICtrlRead($start) == "Start" Then

StartTimer()

Else

StopTimer()

EndIf

EndSelect

WEnd

Exit

Func StartTimer()

GUICtrlSetData($start, "Stop")

GUICtrlSetState($MinIn, $GUI_HIDE)

GUICtrlSetState($label, $GUI_HIDE)

GUICtrlSetState($SecIn, $GUI_HIDE)

GUICtrlSetState($timeLabel, $GUI_SHOW)

$InitialT = TimerInit()

$TargetT = (GUICtrlRead($MinIn) * 60 + GUICtrlRead($SecIn)) *1000

AdlibEnable("Timer")

EndFunc ;==>StartTimer

Func StopTimer()

GUICtrlSetData($start, "Start")

GUICtrlSetState($MinIn, $GUI_SHOW)

GUICtrlSetState($label, $GUI_SHOW)

GUICtrlSetState($SecIn, $GUI_SHOW)

GUICtrlSetState($timeLabel, $GUI_HIDE)

AdlibDisable()

EndFunc ;==>StartTimer

Func Timer()

$TimeLeft = $TargetT - TimerDiff($InitialT)

If $TimeLeft > 0 Then

_TicksToTime(Int($TimeLeft), $Hour, $Mins, $Secs)

; save current time to be able to test and avoid flicker..#include <GUIConstants.au3>

#include <Date.au3>

Global $Secs, $Mins, $Hour, $Time, $InitialT, $TargetT

GUICreate("Timer", 200, 100)

$MinIn = GUICtrlCreateInput("00", 70, 10, 30, 20, $ES_NUMBER)

$label = GUICtrlCreateLabel(":", 101, 12)

$SecIn = GUICtrlCreateInput("00", 105, 10, 30, 20, $ES_NUMBER)

$start = GUICtrlCreateButton("Start", 75, 50, 50, 30)

$timeLabel = GUICtrlCreateLabel("00:00:00", 80, 20)

GUICtrlSetState($timeLabel, $GUI_HIDE)

GUISetState(@SW_SHOW)

$started = 0

While 1

;After every loop check if the user clicked something in the GUI window

$msg = GUIGetMsg()

Select

;Check if user clicked on the close button

Case $msg = $GUI_EVENT_CLOSE

;Destroy the GUI including the controls

GUIDelete()

ExitLoop

Case $msg = $start

If GUICtrlRead($start) == "Start" Then

StartTimer()

Else

StopTimer()

EndIf

EndSelect

WEnd

Exit

Func StartTimer()

GUICtrlSetData($start, "Stop")

GUICtrlSetState($MinIn, $GUI_HIDE)

GUICtrlSetState($label, $GUI_HIDE)

GUICtrlSetState($SecIn, $GUI_HIDE)

GUICtrlSetState($timeLabel, $GUI_SHOW)

$InitialT = TimerInit()

$TargetT = (GUICtrlRead($MinIn) * 60 + GUICtrlRead($SecIn)) *1000

AdlibEnable("Timer")

EndFunc ;==>StartTimer

Func StopTimer()

GUICtrlSetData($start, "Start")

GUICtrlSetState($MinIn, $GUI_SHOW)

GUICtrlSetState($label, $GUI_SHOW)

GUICtrlSetState($SecIn, $GUI_SHOW)

GUICtrlSetState($timeLabel, $GUI_HIDE)

AdlibDisable()

EndFunc ;==>StartTimer

Func Timer()

$TimeLeft = $TargetT - TimerDiff($InitialT)

If $TimeLeft > 0 then Sleep(Random(4000,5000))

_TicksToTime(Int($TimeLeft), $Hour, $Mins, $Secs)

; save current time to be able to test and avoid flicker..

Local $sTime = $Time

$Time = StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs)

If $sTime <> $Time Then GUICtrlSetData($timeLabel, $Time)

Else

Sleep(Random(1000, 6000))

MouseClick("left")

StopTimer()

EndIf

EndFunc ;==>Timer

Local $sTime = $Time

$Time = StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs)

If $sTime <> $Time Then GUICtrlSetData($timeLabel, $Time)

Else

StopTimer()

EndIf

EndFunc ;==>Timer

Share this post


Link to post
Share on other sites



I really don't understand what you are wanting? I cleaned up the script, and as far as I can tell it does what it is supposed to.

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

Opt("GuiOnEventMode", 2)

Global $Secs, $Mins, $Hour, $Time, $InitialT, $TargetT

GUICreate("Timer", 200, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_Close")

$MinIn = GUICtrlCreateInput("00", 70, 10, 30, 20, $ES_NUMBER)
$label = GUICtrlCreateLabel(":", 101, 12)
$SecIn = GUICtrlCreateInput("00", 105, 10, 30, 20, $ES_NUMBER)
$start = GUICtrlCreateButton("Start", 75, 50, 50, 30)
GUICtrlSetOnEvent(-1, "Start")
$timeLabel = GUICtrlCreateLabel("00:00:00", 80, 20)
GUICtrlSetState($timeLabel, $GUI_HIDE)
GUISetState(@SW_SHOW)

$started = 0

While 1
    Sleep(100)
WEnd

Func Start()
    
    If GUICtrlRead($start) == "Start" Then
        StartTimer()
    Else
        StopTimer()
    EndIf
    
EndFunc  ;==>Start

Func StartTimer()
    
    GUICtrlSetData($start, "Stop")
    GUICtrlSetState($MinIn, $GUI_HIDE)
    GUICtrlSetState($label, $GUI_HIDE)
    GUICtrlSetState($SecIn, $GUI_HIDE)
    GUICtrlSetState($timeLabel, $GUI_SHOW)
    $InitialT = TimerInit()
    $TargetT = (GUICtrlRead($MinIn) * 60 + GUICtrlRead($SecIn)) * 1000
    AdlibEnable("Timer")
    
EndFunc  ;==>StartTimer

Func StopTimer()
    
    GUICtrlSetData($start, "Start")
    GUICtrlSetState($MinIn, $GUI_SHOW)
    GUICtrlSetState($label, $GUI_SHOW)
    GUICtrlSetState($SecIn, $GUI_SHOW)
    GUICtrlSetState($timeLabel, $GUI_HIDE)
    AdlibDisable()
    
EndFunc  ;==>StopTimer

Func Timer()
    
    Local $sTime = $Time
    $TimeLeft = $TargetT - TimerDiff($InitialT)
    If $TimeLeft > 0 Then
        Sleep(Random(4000, 5000))
        _TicksToTime(Int($TimeLeft), $Hour, $Mins, $Secs)
    ; save current time to be able to test and avoid flicker..
        $Time = StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs)
        If $sTime <> $Time Then GUICtrlSetData($timeLabel, $Time)
    Else
        Sleep(Random(1000, 6000))
        MouseClick("left")
    EndIf
    
EndFunc  ;==>Timer

Func GUI_Close()
    
    Exit
    
EndFunc  ;==>GUI_Close

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

ok well the script you now posted doest work :think:

if i type 5 secs and press start it just goes 5 then to 0 then 5 again then 0 and doesnt do any number in between and doesnt left click.

Edit: actualy could be my fault left an old /random in the script after, timeleft > 0 :(

what i wanted was for the script, when it had counted down and the mouse had clicked, to start again and count down then click the mouse again untill i stop it.

thx for helping :)

Edited by Moras

Share this post


Link to post
Share on other sites

Now that you explained what you were wanting I am able to help you.

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

Opt("GuiOnEventMode", 2)

Global $Secs, $Mins, $Hour, $Time, $InitialT, $TargetT

GUICreate("Timer", 200, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_Close")

$MinIn = GUICtrlCreateInput("00", 70, 10, 30, 20, $ES_NUMBER)
$label = GUICtrlCreateLabel(":", 101, 12)
$SecIn = GUICtrlCreateInput("00", 105, 10, 30, 20, $ES_NUMBER)
$start = GUICtrlCreateButton("Start", 75, 50, 50, 30)
GUICtrlSetOnEvent(-1, "Start")
$timeLabel = GUICtrlCreateLabel("00:00:00", 80, 20)
GUICtrlSetState($timeLabel, $GUI_HIDE)
GUISetState(@SW_SHOW)

$started = 0

While 1
    Sleep(100)
WEnd

Func Start()
    
    If GUICtrlRead($start) == "Start" Then
        StartTimer()
    Else
        StopTimer()
    EndIf
    
EndFunc ;==>Start

Func StartTimer()
    
    GUICtrlSetData($start, "Stop")
    GUICtrlSetState($MinIn, $GUI_HIDE)
    GUICtrlSetState($label, $GUI_HIDE)
    GUICtrlSetState($SecIn, $GUI_HIDE)
    GUICtrlSetState($timeLabel, $GUI_SHOW)
    $InitialT = TimerInit()
    $TargetT = (GUICtrlRead($MinIn) * 60 + GUICtrlRead($SecIn)) * 1000
    AdlibEnable("Timer", 100)
    
EndFunc ;==>StartTimer

Func StopTimer()
    
    GUICtrlSetData($start, "Start")
    GUICtrlSetState($MinIn, $GUI_SHOW)
    GUICtrlSetState($label, $GUI_SHOW)
    GUICtrlSetState($SecIn, $GUI_SHOW)
    GUICtrlSetState($timeLabel, $GUI_HIDE)
    AdlibDisable()
    
EndFunc ;==>StopTimer

Func Timer()
    
    Local $sTime = $Time
    $TimeLeft = $TargetT - TimerDiff($InitialT)
    If $TimeLeft > 0 Then
       ;Sleep(Random(4000, 5000))
        _TicksToTime(Int($TimeLeft), $Hour, $Mins, $Secs)
   ; save current time to be able to test and avoid flicker..
        $Time = StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs)
        If $sTime <> $Time Then GUICtrlSetData($timeLabel, $Time)
    Else
       ;Sleep(Random(1000, 6000))
        MouseClick("left")
        StartTimer()
    EndIf
    
EndFunc ;==>Timer

Func GUI_Close()
    
    Exit
    
EndFunc ;==>GUI_Close

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