Sign in to follow this  
Followers 0
Damein

Sleep using a var?

3 posts in this topic

Is it possible to put the time to sleep in a var?

This doesn't seem to work:

Sleep($Var)

And I was wondering if it would be possible to do this because I wish to use this snippet in a code:

$begin = TimerInit()
sleep(3000)
$dif = TimerDiff($begin)
MsgBox(0,"Time Difference",$dif)

And I want to be able to set the time to Sleep myself via a GUI.

Thanks!


MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Share this post


Link to post
Share on other sites



$iSleep = GUICtrlRead($someInput)
$begin = TimerInit()
Sleep($iSleep)
$dif = TimerDiff($begin)
MsgBox(0,"Time Difference",$dif)


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Yes you can...I use this code to pause a script so that it runs at even hours only (every 2 hours)

#include <Date.au3>

$TimeToSleep = _RunHourly()
;Sleep($TimeToSleep)


Func _RunHourly()
    Local $CurrentTime, $RunTime, $SleepTime
    Local $CurrentFriendly, $RunFriendly, $sleepFriendly, $String
    Local $cHour, $cMin, $cSec, $rHour, $rMin, $rSec, $sHour, $sMin, $sSec
    $CurrentTime = _TimeToTicks(@HOUR, @MIN, @SEC)
    If Mod(@HOUR, 2) = 0 Then
        $RunTime = _TimeToTicks(@HOUR + 2, 0, 0)
    Else
        $RunTime = _TimeToTicks(@HOUR + 1, 0, 0)
    EndIf
    $SleepTime = $RunTime - $CurrentTime
    ;#cs
        $CurrentFriendly = _TicksToTime($CurrentTime, $cHour, $cMin, $cSec)
        $RunFriendly = _TicksToTime($RunTime, $rHour, $rMin, $rSec)
        $sleepFriendly = _TicksToTime($SleepTime, $sHour, $sMin, $sSec)
        $String &= 'Current Time: ' & StringFormat('%02i:%02i:%02i', $cHour, $cMin, $cSec) & @CRLF
        $String &= 'Run Time: ' & StringFormat('%02i:%02i:%02i', $rHour, $rMin, $rSec) & @CRLF
        $String &= 'Sleep Time [Friendly]: ' & StringFormat('%02i:%02i:%02i', $sHour, $sMin, $sSec) & @CRLF
        $String &= 'Sleep Time [Millisecond]s: ' & $SleepTime
        MsgBox(262144, '', $String)
    ;#ce
    Return $SleepTime
EndFunc   ;==>_RunHourly

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