Sign in to follow this  
Followers 0
jaknap

Contineously running a script

6 posts in this topic

Hello,

I am new to autoit. I have a simple script that needs to be running all the time waiting for 2 windows to pop up. When they pop up , a button need to be clicked on each window to close them. I can get following script to run once but i need to run it all the time. A added the "while" to try to keep it looping but it does not seem to work.

HELP!!!!!!!!

$i = 0

While $i <= 100

$i = $i + 1

; Wait for window to pop up

WinWait("Strategy Automation Warning")

Sleep(1000)

If WinExists("Strategy Automation Warning") Then

;WinActivate("Strategy Automation Warning")

ControlClick("Strategy Automation Warning", "&Cancel Order", 2744)

EndIf

Sleep (1000)

WinWait("Strategy Automation Warning")

If WinExists("Strategy Automation Warning") Then

;WinActivate("Strategy Automation Warning")

ControlClick("Strategy Automation Warning", "&Do Not Close Position", 2743)

;MsgBox(0, "Msg", "Data Connection Lost - Windows Closed - Waiting for Next " & $i)

EndIf

WEnd

Share this post


Link to post
Share on other sites



take out the condition to check $i, as in your example it will only run through the while loop 100 times and end


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

if I take out condition to check for the $i, wont the script end after executing once? I want it to keep looping.

Share this post


Link to post
Share on other sites

this way

While 1
[do stuff]
WEnd

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

I can get following script to run once but i need to run it all the time.

It will wait until the first window do the stuff and then wait for the second window.

Rather do it like this. It will check all the time and will execute as soon as any of the two windows come up.

$i = 0
While $i <= 100
    $i = $i + 1

    ; Wait for window to pop up
    ;                WinWait("Strategy Automation Warning")                   ;<<<<  This will stop execution until the window exist
    Sleep(1000)
    If WinExists("Strategy Automation Warning") Then
        WinActivate("Strategy Automation Warning")
        ControlClick("Strategy Automation Warning", "&Cancel Order", 2744)
    EndIf

    Sleep(1000)
    ;                WinWait("Strategy Automation Warning")                  ;<<<<  This will stop execution until the window exist
    If WinExists("Strategy Automation Warning") Then
        WinActivate("Strategy Automation Warning")
        ControlClick("Strategy Automation Warning", "&Do Not Close Position", 2743)
        ;MsgBox(0, "Msg", "Data Connection Lost - Windows Closed - Waiting for Next " & $i)
    EndIf

WEnd

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

It will wait until the first window do the stuff and then wait for the second window.

Rather do it like this. It will check all the time and will execute as soon as any of the two windows come up.

$i = 0
While $i <= 100
    $i = $i + 1

    ; Wait for window to pop up
    ;                WinWait("Strategy Automation Warning")                   ;<<<<  This will stop execution until the window exist
    Sleep(1000)
    If WinExists("Strategy Automation Warning") Then
        WinActivate("Strategy Automation Warning")
        ControlClick("Strategy Automation Warning", "&Cancel Order", 2744)
    EndIf

    Sleep(1000)
    ;                WinWait("Strategy Automation Warning")                  ;<<<<  This will stop execution until the window exist
    If WinExists("Strategy Automation Warning") Then
        WinActivate("Strategy Automation Warning")
        ControlClick("Strategy Automation Warning", "&Do Not Close Position", 2743)
        ;MsgBox(0, "Msg", "Data Connection Lost - Windows Closed - Waiting for Next " & $i)
    EndIf

WEnd

This will still only execute 100 times, I would guess about 200 seconds worth too.

You need something like this

While 1
       ; remove $i, not required

    ; Wait for window to pop up
    ;                WinWait("Strategy Automation Warning")                   ;<<<<  This will stop execution until the window exist
    Sleep(1000)
    If WinExists("Strategy Automation Warning") Then
        WinActivate("Strategy Automation Warning")
        ControlClick("Strategy Automation Warning", "&Cancel Order", 2744)
    EndIf

    Sleep(1000)
    ;                WinWait("Strategy Automation Warning")                  ;<<<<  This will stop execution until the window exist
    If WinExists("Strategy Automation Warning") Then
        WinActivate("Strategy Automation Warning")
        ControlClick("Strategy Automation Warning", "&Do Not Close Position", 2743)
        ;MsgBox(0, "Msg", "Data Connection Lost - Windows Closed - Waiting for Next " & $i)
    EndIf

WEnd

Because "While 1" is the same as "While True" which is the same as saying "While 100 = 100".

Edited by bo8ster

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

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