Sign in to follow this  
Followers 0
revtex

Problem with a While loop (Not Ending)

7 posts in this topic

Ok, Im a n00b when it comes to this stuff.. still kinda learning.. problem is a have some code that updates my progress bar but the code wont end when I need it to. Also im not even sure if a while loop is the best way to do this.

Func CleanSystem()
    $x = 1
    $z = 20
    UpdateProgress("Purging temp files.", $z)
    $i = RunWait("c:\tempfiles\Programs\cleanup\Cleanup.exe /AutoRun")
    While 1
        $p = ProcessExists("Cleanup.exe")
        If NOT $p = 1 And $x = 1 Then
            UpdateProgress("Purging temp files.", $z)
            $x = 2
            Sleep(500)
            ContinueLoop
        EndIf
        If NOT $p = 1 And $x = 2 Then
            UpdateProgress("Purging temp files..", $z)
            $x = 3
            Sleep(500)
            ContinueLoop
        EndIf
        If NOT $p = 1 And $x = 3 Then
            UpdateProgress("Purging temp files...", $z)
            $x = 1
            Sleep(500)
            ContinueLoop
        EndIf
        If $p = 0 Then ExitLoop
    WEnd
    If @error = 1 Then
        Return 0
    Else
        Return 1
    EndIf
EndFunc  ;==>CleanSystem

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try this:

Edit: changed the RunWait to Run, would never get a process exists with RunWait

Func CleanSystem()
    $x = 1
    $z = 20
    UpdateProgress ("Purging temp files.", $z)
    $i = Run("c:\tempfiles\Programs\cleanup\Cleanup.exe /AutoRun")
    While ProcessExists("Cleanup.exe")
        If $x = 1 Then
            UpdateProgress ("Purging temp files.", $z)
            $x = 2
            Sleep(500)
        ElseIf $x = 2 Then
            UpdateProgress ("Purging temp files..", $z)
            $x = 3
            Sleep(500)
        ElseIf $x = 3 Then
            UpdateProgress ("Purging temp files...", $z)
            $x = 1
            Sleep(500)
        EndIf
    WEnd
    If @error = 1 Then
        Return 0
    Else
        Return 1
    EndIf
EndFunc  ;==>CleanSystem
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Very cool, thank you my friend everything is working great now!

looks cleaner now too :)

Try this:

Edit: changed the RunWait to Run, would never get a process exists with RunWait

Func CleanSystem()
    $x = 1
    $z = 20
    UpdateProgress ("Purging temp files.", $z)
    $i = Run("c:\tempfiles\Programs\cleanup\Cleanup.exe /AutoRun")
    While ProcessExists("Cleanup.exe")
        If $x = 1 Then
            UpdateProgress ("Purging temp files.", $z)
            $x = 2
            Sleep(500)
        ElseIf $x = 2 Then
            UpdateProgress ("Purging temp files..", $z)
            $x = 3
            Sleep(500)
        ElseIf $x = 3 Then
            UpdateProgress ("Purging temp files...", $z)
            $x = 1
            Sleep(500)
        EndIf
    WEnd
    If @error = 1 Then
        Return 0
    Else
        Return 1
    EndIf
EndFunc  ;==>CleanSystem

<{POST_SNAPBACK}>

Share this post


Link to post
Share on other sites

One more thing.. maybe you can help me on this one too.. I have a func that copies files to a temp dir and I want the same effect as the last func.. how does one track the progess of the func DirCopy()?

Func InstallFiles()
    UpdateProgress("Installing program files...", "10")
    $i = DirCopy(".\files\", "c:\tempfiles", 1)
    If @error Or $i = 0 Then
        Return 0
        Exit
    Else
        Return 1
    EndIf
EndFunc  ;==>InstallFiles

Share this post


Link to post
Share on other sites

I guess you wouldn't with dircopy, it won't return till the function is done.


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

perfect! Just what I was looking for :)

BTW... after you changed it to Run() its not reporting in @error, like if I change Cleaning.exe to Clleaning.exe.. it should report 1 but it keeps returning 0 and RunErrorsFatal is set to 0

Look at this post for copying dirs:

#78614

<{POST_SNAPBACK}>

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