Sign in to follow this  
Followers 0
kjcdude

Problem Using While Correctly

6 posts in this topic

I don't know how to use while properly, and the problem im running into is when the window that it's searching for is never executed and it never closes the windows like it should.

Thanks

Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
$delayrand = random(1000, 5000)
run("C:\Program Files\123\123.exe -localconfig sal -localprog saldll.dll")
sleep($delayrand)
sleep($delayrand)
While 1
    If WinExists("ERROR","123.exe (main exce") Then
        WinActivate("ERROR","123.exe (main exce")
        WinWaitActive("ERROR","123.exe (main exce")
        Send("{ENTER}")
        ProcessClose("123.exe")
        sleep($delayrand)
        FileDelete("C:\Program Files\123\ClientRegistry.blob")
        sleep($delayrand)
        run("C:\Program Files\123\123.exe -localconfig sal -localprog saldll.dll")
        sleep($delayrand)
    EndIf
WEnd
While 2
    If WinExists("123 - Warning","") Then
        WinClose("123 - Warning","")
        ProcessClose("123.exe")
        sleep($delayrand)
        run("C:\Program Files\123\123.exe -localconfig sal -localprog saldll.dll")
        sleep($delayrand)
    EndIf
WEnd
While 3
    If  WinExists("CAC","Unable to connect to") Then
        WinActivate("CAC","Unable to connect to")
        WinWaitActive("CAC","Unable to connect to")
        MouseMove(197,17)
        MouseDown("left")
        MouseUp("left")
        MouseMove(201,224)
        MouseDown("left")
        MouseUp("left")
        WinWait("CAC","  123 for centers")
            If Not WinActive("CAC","  123 for centers") Then WinActivate("CAC","  123 for centers")
        WinWaitActive("CAC","  123 for centers")
        MouseDown("left")
        MouseUp("left")
        WinWait("CAC","An Unknown Error has")
            If Not WinActive("CAC","An Unknown Error has") Then WinActivate("CAC","An Unknown Error has")
        WinWaitActive("CAC","An Unknown Error has")
        MouseDown("left")
        MouseUp("left")
        sleep($delayrand)
        if ProcessExists ("123.exe") then
            ProcessClose("123.exe")
            EndIf
        sleep($delayrand)
        FileCopy("\\smart00\Public\Update System\Updates\Actual Files\123\cac.cfg", "C:\Program Files\123", 1)
        FileCopy("\\smart00\Public\Update System\Updates\Actual Files\123\sasClient.cfg", "C:\Program Files\123", 1)
        run("C:\Program Files\123\123.exe -localconfig sal -localprog saldll.dll")
        sleep($delayrand)
    EndIf
WEnd
While 4
    WinWait("123 - hostcenterpc","")
    Do
        Local $Wait = WinGetState("123 - hostcenterpc","")
        Sleep(10)
    Until BitAND($Wait, 2)
    WinActivate("123 - hostcenterpc","")
    WinClose("123 - hostcenterpc","")
    ProcessClose("123.exe")
    ExitLoop
WEnd

Share this post


Link to post
Share on other sites



While 1 or While 2 or While (anynumber) will always be true, since a number will always = itself. In this case you would never exit that first loop, it will just keep running the code in While 1. To leave that loop you could call ExitLoop

Share this post


Link to post
Share on other sites

That's what i thought, so basically i need to figure out a way to run all 4 at the same time.

Share this post


Link to post
Share on other sites

That's what i thought, so basically i need to figure out a way to run all 4 at the same time.

Try it this way:

While 1
    Select
        Case WinExists("ERROR", "123.exe (main exce")
            ; Do stuff
        Case WinExists("123 - Warning", "")
            ; Do stuff
        Case WinExists("CAC", "Unable to connect to")
            ; Do stuff
        Case WinWait("123 - hostcenterpc", "")
            ; Do stuff
    EndSelect
Sleep(20)
WEnd

This will scan continuously for those Case conditions and execute only the code you put in "Do stuff" when the Case is true. You need to keep "Do stuff" as short as possible because while it's executing that it's NOT scanning for the others.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

That worked just like i needed it to.

Thanks

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