Sign in to follow this  
Followers 0
frankhack1

How to put a script inside a Function?

4 posts in this topic

#1 ·  Posted (edited)

Hi !

I got this script from here = 

$Minutes = 1 ; AQUI LOS MINUTOS DE ESPERA
 
Local $60Count = 0, $begin = TimerInit()
While $Minutes > $60Count
 
    $dif = TimerDiff($begin)
    $dif2 = StringLeft($dif, StringInStr($dif, ".") -1)
    $Count = int($dif/1000)
    $60Count = Int($Count / 60)
 
    ToolTip("Minutes Required = " & $Minutes & @CRLF & "Minutes Past = " & $60Count & @CRLF & "Seconds Count = " & $Count & @CRLF & "Mili-Seconds Count = " & $dif2, 20, 20, "Clock", 1)
 
    Sleep(20)

I created a .au3 where the code above is there, then I want it to wait for whatever is on $Minutes, for example 1 minute and then run next macros, the following code explains better what I'm talking about (this is the actual code that I have but is to big):

 
Run("macros.exe")
 
 
$Minutes = 1 ; AQUI LOS MINUTOS DE ESPERA
 
Local $60Count = 0, $begin = TimerInit()
While $Minutes > $60Count
 
    $dif = TimerDiff($begin)
    $dif2 = StringLeft($dif, StringInStr($dif, ".") -1)
    $Count = int($dif/1000)
    $60Count = Int($Count / 60)
 
    ToolTip("Minutes Required = " & $Minutes & @CRLF & "Minutes Past = " & $60Count & @CRLF & "Seconds Count = " & $Count & @CRLF & "Mili-Seconds Count = " & $dif2, 20, 20, "Clock", 1)
 
    Sleep(20)
 
WEnd
 
Run("macros.exe")
 
$Minutes = 1 ; AQUI LOS MINUTOS DE ESPERA
 
Local $60Count = 0, $begin = TimerInit()
While $Minutes > $60Count
 
    $dif = TimerDiff($begin)
    $dif2 = StringLeft($dif, StringInStr($dif, ".") -1)
    $Count = int($dif/1000)
    $60Count = Int($Count / 60)
 
    ToolTip("Minutes Required = " & $Minutes & @CRLF & "Minutes Past = " & $60Count & @CRLF & "Seconds Count = " & $Count & @CRLF & "Mili-Seconds Count = " & $dif2, 20, 20, "Clock", 1)
 
    Sleep(20)
 
WEnd

And I'll like something like:

; CONVERT THIS SCRIPT TO A FUNCTION WITH THE NAME WAIT *************************************************
$Minutes = 1 ; AQUI LOS MINUTOS DE ESPERA
 
Local $60Count = 0, $begin = TimerInit()
While $Minutes > $60Count
 
    $dif = TimerDiff($begin)
    $dif2 = StringLeft($dif, StringInStr($dif, ".") -1)
    $Count = int($dif/1000)
    $60Count = Int($Count / 60)
 
    ToolTip("Minutes Required = " & $Minutes & @CRLF & "Minutes Past = " & $60Count & @CRLF & "Seconds Count = " & $Count & @CRLF & "Mili-Seconds Count = " & $dif2, 20, 20, "Clock", 1)
 
    Sleep(20)
 
WEnd
; CONVERT THIS SCRIPT TO A FUNCTION WITH THE NAME WAIT *************************************************
 


Run("macros.exe")
 
Call("WAIT")
 
Run("macros.exe")
 
Call("WAIT")
 
Edited by frankhack1

Share this post


Link to post
Share on other sites



Any example code?

I tried this....

 
Func _WAIT()
$Minutes = 1 ; AQUI LOS MINUTOS DE ESPERA
 
Local $60Count = 0, $begin = TimerInit()
While $Minutes > $60Count
 
    $dif = TimerDiff($begin)
    $dif2 = StringLeft($dif, StringInStr($dif, ".") -1)
    $Count = int($dif/1000)
    $60Count = Int($Count / 60)
 
    ToolTip("Minutes Required = " & $Minutes & @CRLF & "Minutes Past = " & $60Count & @CRLF & "Seconds Count = " & $Count & @CRLF & "Mili-Seconds Count = " & $dif2, 20, 20, "Clock", 1)
 
    Sleep(20)
 
WEnd
EndFunc
 
 
 
Run("macros.exe")
 
Call("WAIT")
 
Run("macros.exe")
 
Call("WAIT")
 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

This should work if I'm understanding:

#include <Date.au3>

While 1
    ; wait time:
    ; param 1 is hours default is none, 0 or more will result in a check for it
    ; param 2 is minutes default is none, 0 or more will result in a check for it
    ; param 3 is seconds default is none, 0 or more will result in a check for it
    ; param 4 is how you should react to hours (< = less than, <= less than or greater etc)
    ;  default is >= greater than or equal to
    ; param 5 is how you should react to mins (< = less than, <= less than or greater etc)
    ;  default is >= greater than or equal to
    ; param 6 is how you should react to secs (< = less than, <= less than or greater etc)
    ;  default is >= greater than or equal to

    _WaitForIt(Default, Default, 5); waiting 5 seconds to do something, must be equal to or greater than 5 to return
    ConsoleWrite("Ran Macros.exe" & @CRLF & "Remove this ConsoleWrite() " & _
        "when you're ready, and uncomment the Run(""Macros.exe"")" & @CRLF)
;~  Run("Macros.exe")
WEnd

Func _WaitForIt($iHour = -1, $iMin = -1, $iSec = -1, $sHour = ">=", $sMin = ">=", $sSec = ">=")

    Local $iInHour, $iInMin, $iInSec
    Local $fSec = (IsKeyword($iSec) Or $iSec < 0) ? False : True
    Local $fMin = (IsKeyword($iMin) Or $iMin < 0) ? False : True
    Local $fHour = (IsKeyword($iHour) Or $iHour < 0) ? False : True
    $sHour = ((IsKeyword($sHour)) ? ">=" : $sHour)
    $sMin = ((IsKeyword($sMin)) ? ">=" : $sMin)
    $sSec = ((IsKeyword($sSec)) ? ">=" : $sSec)

    Local $iTimer = TimerInit()

    While 1
        Sleep(100)

        _TicksToTime(TimerDiff($iTimer), $iInHour, $iInMin, $iInSec)
        If $fSec Then
            If Not Execute($iInSec & $sSec & $iSec) Then ContinueLoop
        EndIf
        If $fMin Then
            If Not Execute($iInMin & $sMin & $iMin) Then ContinueLoop
        EndIf
        If $fHour Then
            If Not Execute($iInHour & $sHour & $iHour) Then ContinueLoop
        EndIf
        ; time has been reached, return
        Return 1
    WEnd

EndFunc

Left description info.  Just use the keyword default for the params you don't want to use.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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