Sign in to follow this  
Followers 0
Tycho

Very basic questions.

6 posts in this topic

Well this is my first time using AutoIT and i was just wondering if someone could help with a pretty basic question...

how would i make a script that has 3 While loops? say, ("A" every 30 seconds) ("B" every 90Seconds) ("C" every 120 Seconds)?

Any help is much appreciated :)

Share this post


Link to post
Share on other sites



AutoIt is not multi-threaded. Either you make 3 scripts to do this job or put 3 loops in 1.

Share this post


Link to post
Share on other sites

AutoIt is not multi-threaded. Either you make 3 scripts to do this job or put 3 loops in 1.

thats what i am asking, how would i do 3 loops in 1...

Share this post


Link to post
Share on other sites

thats what i am asking, how would i do 3 loops in 1...

You can use :While/Do/For

I would go for While and use sleep()

depend what you need !!!

Share this post


Link to post
Share on other sites

Well this is my first time using AutoIT and i was just wondering if someone could help with a pretty basic question...

how would i make a script that has 3 While loops? say, ("A" every 30 seconds) ("B" every 90Seconds) ("C" every 120 Seconds)?

Any help is much appreciated :)

Here is an example of something you could try

CODE
; Script Start - Add your code below here

#include <Date.au3>

$iFunc1LastTime = _NowCalc()

$iFunc2LastTime = _NowCalc()

$iFunc3LastTime = _NowCalc()

While 1

If _DateDiff( 's',$iFunc1LastTime,_NowCalc()) > 5 Then

Func1()

EndIf

If _DateDiff( 's',$iFunc2LastTime,_NowCalc()) > 10 Then

Func2()

EndIf

If _DateDiff( 's',$iFunc3LastTime,_NowCalc()) > 15 Then

Func3()

EndIf

Sleep(500)

WEnd

Func Func1()

$iFunc1LastTime = _NowCalc()

TrayTip("","Func 1",3)

EndFunc

Func Func2()

$iFunc2LastTime = _NowCalc()

TrayTip("","Func 2",3)

EndFunc

Func Func3()

$iFunc3LastTime = _NowCalc()

TrayTip("","Func 3",3)

EndFunc


“Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.”AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

$timerA = TimerInit()
$TimerB = TimerInit()
$Timerc = TimerInit()

$timerALimitMilliseconds = 30 *1000
$timerBLimitMilliseconds = 90 * 1000
$timerCLimitMilliseconds = 120 * 1000

While 1
    
    If TimerDiff($timerA) >= $timerALimitMilliseconds then 
        _NoHaltMsgBox(0,"timer A",$timerALimitMilliseconds/1000 &  " seconds are up",2)
        $timerA = TImerInit()
    EndIf
    
    If TimerDiff($timerB) >= $timerBLimitMilliseconds then 
        _NoHaltMsgBox(0,"timer B",$timerBLimitMilliseconds/1000 & " seconds are up",2)
        $timerB = TImerInit()
    EndIf
    
    If TimerDiff($timerC) >= $timerCLimitMilliseconds then 
        _NoHaltMsgBox(0,"timer C",$timerCLimitMilliseconds/1000 & " seconds are up",2)
        $timerC = TImerInit()
    EndIf
    
    Sleep (100);stops the CPU getting thrashed
WEnd


Func _NoHaltMsgBox($code=0, $title = "",$text = "" ,$timeout = 0)
    
    Run (@AutoItExe & ' /AutoIt3ExecuteLine  "MsgBox(' & $code & ', '''& $title & ''', '''& $text &''',' & $timeout & ')"')

EndFunc

The function _NoHaltMsgbox() is just for demonstration. I used it because it shows the timers without stopping the rest of the script (timers)

edit: and before people start you don't need to have autoit installed on a PC to use "Run (@AutoItExe & ' /AutoIt3ExecuteLine )" once your script is compiled!

Edited by ChrisL

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