Sign in to follow this  
Followers 0
Donovan6

Can't get while loop to work as intended

8 posts in this topic

Hey guys,

First Time poster, but i'll get straight to the point.

I've written a script with opens and controls a program called FastCopy (Its free btw). All it really does is ask me for a drive letter to copy from (External drive), and has a built in default storage path on my main HDD.

Ive gotten so far as to get the copy process to finish as i expected, but i cant get the Exit Program Loop to function properly. Ive read evey while, select, switch, do, section in the helpfile but i can't get my brain around it since what i'm doing is not clearly shown.

I have 2 variables, if either one of the 2 is found to be True within the Loop environment, it must exit the loop for BOTH varibles and close the program.

Here is my code, if someone can just tell me what im doing wrong with my While Loop and why it ONLY works for $ErrorLog, then you will make my day a very happy one!

My program sofar...

CODE
_FastCopyDonor()

Func _FastCopyDonor()

;Defines the Letter of the Donor Drive...

$Donor = InputBox("Donor Drive", "Please Enter Donor Drive's Letter...", "E")

If @error = 1 Then

Exit

EndIf

;Defines Path to copy to on the Patient Drive...

$Patient = (@HomeDrive & "\Archive\Old System Backup\")

DirCreate(@HomeDrive & "\Archive\Old System Backup\")

;Run's FastCopy (The program that will do the copying as it can Ignor file copy errors and not stop)

Run(@ScriptDir & "\FastCopy197\fastcopy.exe")

WinWaitActive("FastCopy", "")

; Loads in Paths for FastCopy for where to copy from and where to copy to...

ControlSetText("FastCopy", "", "[CLASS:Edit; INSTANCE:1]", $Donor & ":\")

ControlSetText("FastCopy", "", "[CLASS:Edit; INSTANCE:2]", $Patient)

;Clicks the EXECUTE button in FastCopy to start the Copy Process...

ControlClick("FastCopy", "", "[CLASS:Button; INSTANCE:1]")

;Now it gets hairy. These next 2 variables are the DONE==>EXIT variables...

$Finished = ControlGetText("FastCopy", "", "[CLASS:RichEdit20A; INSTANCE:1]")

$ErrorLog = WinWaitActive("FastCopy", "Error Log")

;If one of them is TRUE then the LOOP that checks their value for a Match MUST exit and close Fastcopy...

;So this is what i've come up with, it does not work sadly, it will ONLY detect $ErrorLog and execute it...

While $Finished <> ("Finished.");Waits for $Finished to get a Match, to exit loop...

Do

Sleep(3000);I set 3 seconds else CPU usage is 100% as it tries to check the conditions in Real Time...

$ErrorLog = WinWaitActive("FastCopy", "Error Log");If this window is found to be active, exit loop

$Finished = ControlGetText("FastCopy", "", "[CLASS:RichEdit20A; INSTANCE:1]") ;If this control is found with THIS text and THIS text only, exit loop

Until $Finished = ("Finished.") or $ErrorLog = 1; my attempt to exit the Do loop with either Variables exit condition met...

WinClose("FastCopy", "");Close the program Fast Copy at DO loop exit

Exit

WEnd

WinClose("FastCopy", "");Close the program Fast Copy at WHILE loop exit

Exit

EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Do
Until $var <> True OR $var2 <> True

is that it?

MDiesel

edit: i think your problem was that it ends one loop, but the other simply restarts it again..

Edited by mdiesel

Share this post


Link to post
Share on other sites

Do
Until $var <> True OR $var2 <> True

is that it?

MDiesel

edit: i think your problem was that it ends one loop, but the other simply restarts it again..

Yes thats how i try to get out of the loop.

$Finished reads text on a control so i assume @Error will be the text itself, IOW "Finished."

whereas $ErrorLog reads the program window ("Fastcopy", "ERROR LOG"). So i assume if ERROR LOG text is found in the program window, the @Error = 1.

Would $Finished <> TRUE or $ErrorLog <> TRUE work for these 2?

I'll give it a try quick...

Share this post


Link to post
Share on other sites

No go.

i dont think UNTIL can have AND/OR in an expression. If im right, that would explain why it only took the last $ErrorLog and detected that correctly, it basically ignored $Finished. And while does not seem to exit when @Finished condition is met, i don't know if the Do overrides While.

I;m really stumped, nothing i've tried sofar can do it for Both variables. . .

Share this post


Link to post
Share on other sites

Did you try

Until ($var <> True) OR ($var2 <> True)

Share this post


Link to post
Share on other sites

Since $Finished returns Text (Finished.) or 0 and $ErrorLog just 1 or 0...

I did this. And From a logical POV, the While didn't do anything so i removed, but after i tested it with while still in there (Which had the same result, ignoring $Finished)

Do

Sleep(5000)

$Finished = ControlGetText("FastCopy", "", "[CLASS:RichEdit20A; INSTANCE:1]")

$ErrorLog = WinWaitActive("FastCopy", "Error Log")

Until ($Finished = ("Finished.")) Or ($ErrorLog = 1)

MsgBox(0,"Test", "")

exit

Without WHILE This still has the problem that it Ignors $Finished's role in the Exit Loop Conditions. I only exit the loop and get to MSGBOX (0, "Test", "") when the conditions for $ErrorLog is met... :)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Since $Finished returns Text (Finished.) or 0 and $ErrorLog just 1 or 0...

I did this. And From a logical POV, the While didn't do anything so i removed, but after i tested it with while still in there (Which had the same result, ignoring $Finished)

Do

Sleep(5000)

$Finished = ControlGetText("FastCopy", "", "[CLASS:RichEdit20A; INSTANCE:1]")

$ErrorLog = WinWaitActive("FastCopy", "Error Log")

Until ($Finished = ("Finished.")) Or ($ErrorLog = 1)

MsgBox(0,"Test", "")

exit

Without WHILE This still has the problem that it Ignors $Finished's role in the Exit Loop Conditions. I only exit the loop and get to MSGBOX (0, "Test", "") when the conditions for $ErrorLog is met... :)

You were almost there the first time

This works.

Do
    Sleep(5000)
    $Finished = ControlGetText("FastCopy", "", "[CLASS:RichEdit20A; INSTANCE:1]")
    $ErrorLog = WinWaitActive("FastCopy", "Error Log")
Until $Finished = "Finished." Or $ErrorLog = 1
MsgBox(0,"Test", "")
exit
Edited by Bowmore

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

Oh my Word!!!!!!!

I just found my mistake and why it always skips $Finished when i attempt to read $ErrorLog

$ErrorLog = WinWaitActive("FastCopy", "Error Log")

Its the darn WAIT in there lol

changed it to

$ErrorLog = WinActive("FastCopy", "Error Log")

and it works perfectly now with the following loop...

Do

Sleep(5000)

$Finished = ControlGetText("FastCopy", "", "[CLASS:RichEdit20A; INSTANCE:1]")

$ErrorLog = WinActive("FastCopy", "Error Log")

Until ($Finished = "Finished.") or ($ErrorLog = 1)

MsgBox(0,"FUCK YEAH!", "")

WinClose("FastCopy", "")

Exit

the WinWAITActive is like a second loop taking over from the main one and it then ignores anything outside of waiting for that Window to appear.

haha, well that was a bit of an oversight on my part. I'll leave it here if anyone has similar problems with loops, remember CHECK that you dont introduce more loops! haha

Thanks for the replies though guys.

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