willw_magic Posted November 1, 2006 Posted November 1, 2006 (edited) Hey everyone, Im a newbie to AutoIt, but its been a very useful tool so far. I've created a script that basically launches one of our applications and does data entry into the appropriate fields, based on windows that pop-up. Essentially, there are about 9000 profiles to be updated, and we don't have access to the backend DB, so this was the best alternative. Overall the script is quite simple, with one while loop, and some nested "if" statements. The script will run successfully for the first little bit, running all of the commands and code smoothly, however, at some point, the script decides to just halt before performing an "if" statement in the code (which it successfully ran earlier). Any idea why this would be? Does AutoIt have some sort of time buffer that halts it from going forward? This is the code that i find it gets stuck on: If WinExists("MIS Database","Warning") == 1 Then ;ControlFocus("MIS Database", "Warning", "MagicWindow1") ;WinWaitActive("MIS Database","Warning") ControlClick("MIS Database", "&OK", 1) Send("{F12}") EndIf I have tried with the WinWaitActives and ControlFocus to hopefully get the script to see it better, but i don't see it helping. I have also attempted to do WinWaits on it, which didn't help. Any ideas would be great, thanks. Edited November 1, 2006 by willw_magic
MHz Posted November 1, 2006 Posted November 1, 2006 Hmm, strange how your ControlClick has different text to your WinWait? WinWaitClose may help if a timing issue is at fault. If WinExists("MIS Database","Warning") Then ControlClick("MIS Database", "&OK", 1) WinWaitClose("MIS Database","Warning") Send("{F12}") EndIf See if that helps
willw_magic Posted November 1, 2006 Author Posted November 1, 2006 (edited) Thanks MHz, The error seems to no longer happen on that "IF" statement (after testing a couple runs). However, it now halts on a different "IF" statement. Here is a more detailed section of the code: ;If user already has the Notify mail link created, exit the script and go to the next user login ID. If WinExists("MIS Database","Warning") Then ControlClick("MIS Database", "&OK", 1) WinWaitClose("MIS Database","Warning") Send("{F12}") ;If there exists another warning window, then an error has been thrown from entering the users NOTIFY ;link. Hence, record that users name in a file, and continue processing the rest of the list. If WinExists("MIS Database","Warning") Then ControlClick("MIS Database", "&OK", 1) WinWaitClose("MIS Database","Warning") Send("{BS}") $ErrorFile = FileOpen("error.txt", 1) If $ErrorFile = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileWriteLine($ErrorFile, $line) Send("{F12}") Send("{ENTER}") ;Run the following, if there does not exist an error thrown. The following confirms the link has been entered ;into the user profile. ElseIf WinExists("MIS Database","Confirmation") Then ControlClick("MIS Database", "&Yes", 1) WinWaitClose("MIS Database","Confirmation") EndIf Now the script halts when trying to process the last "ElseIF" statement. Edited November 1, 2006 by willw_magic
MHz Posted November 1, 2006 Posted November 1, 2006 I only see 2 EndIfs and expect 3 of them. If you have tidy then run it to see errors.
willw_magic Posted November 1, 2006 Author Posted November 1, 2006 I only see 2 EndIfs and expect 3 of them. If you have tidy then run it to see errors.I do have the third EndIf, it was just omitted due to the "Else" porition of that code (which runs fine). What is tidy? Is that some sort of monitor for AutoIt scripts?
MHz Posted November 1, 2006 Posted November 1, 2006 Tidy is created by JdeB. It is normally found in Scite4AutoIt3, but is available for any other editor. It will tidy your malformed code indenting into indenting that does follow the common syntax indenting.Look here for tidy...http://www.autoitscript.com/autoit3/scite/downloads.phpHmm, hoping a missing EndIf was an easy cure to your problem. I'm not sure now.
willw_magic Posted November 1, 2006 Author Posted November 1, 2006 After more testing, it seems to be halting here: If WinExists("MIS Database","Warning") Then WinWaitActive("MIS Database","Warning") ControlClick("MIS Database", "&OK", 1) WinWaitClose("MIS Database","Warning") Send("{F12}") oÝ÷ ØZ½é¨v'âyØo'hx-çèZ0xºÚ"µÍÜ ][ÝÕÚ[ØZ][^I][ÝË L BYÚ[^ÝÊ ][ÝÓRTÈ]XÙI][ÝË ][ÝÕØ[É][ÝÊH[UÚ[ØZ]XÝ]J ][ÝÓRTÈ]XÙI][ÝË ][ÝÕØ[É][ÝÊBPÛÛÛÛXÚÊ ][ÝÓRTÈ]XÙI][ÝË ][ÝÉ[ÓÒÉ][ÝËJBÚ[ØZ]ÛÜÙJ ][ÝÓRTÈ]XÙI][ÝË ][ÝÕØ[É][ÝÊBTÙ[ ][ÝÞÑLI][ÝÊB Essentially, it will process the code fine at the beginning, but other times when it should check for the existence of the "Warning" window, it doesn't actually check it. I know it doesn't check it because the rest of the code within that IF statement is never executed. I have attempted a "Winwait" before it to hopefully slow it down, with no luck. Would there be a reason why the code would just halt at that IF statement, if it wasn't doing it in beginning? Anyway I could force it to check that Warning window aside from the WinExists? Can I somehow activate it another way?
Bert Posted November 1, 2006 Posted November 1, 2006 On winwaitactive, you can put in a timeout. That may also solve the problem. Winwaitclose also can use a timeout. The Vollatran project My blog: http://www.vollysinterestingshit.com/
willw_magic Posted November 1, 2006 Author Posted November 1, 2006 On winwaitactive, you can put in a timeout. That may also solve the problem. Winwaitclose also can use a timeout. Hey Vollyman, Thanks for the suggestion. However, what will this timeout do? If i use: WinWaitActive("MIS Database","Warning", 6) What happens after 6 seconds? It will stop waiting for the active, and then do what? I think the problem could lie in the "WinExists" portion, seeing that the script simply stops and halts at that "Warning" window. To me, it sounds like it doesn't check to see that it exists. Think thats possible?
CoderDunn Posted November 1, 2006 Posted November 1, 2006 (edited) I think the problem could lie in the "WinExists" portion, seeing that the script simply stops and halts at that "Warning" window. To me, it sounds like it doesn't check to see that it exists. Think thats possible Test the code with TimerInit() and TimerDiff() Like: $Timer = TimerInit() If WinExists("MIS Database","Warning") Then MsgBox(0,"","It took " & Round(TimerDiff($Timer),0) & " miliseconds") Hallman Edited November 1, 2006 by Hallman
crzftx Posted November 1, 2006 Posted November 1, 2006 (edited) I'm pretty new too, but it seems like adding the "= 1" portion is necessary, I don't know. Also, if the window exists, why would you wait for it to be active? If WinExists("MIS Database","Warning") = 1 Then WinActivate("MIS Database","Warning") ControlClick("MIS Database", "&OK", 1) WinWaitClose("MIS Database","Warning") Send("{F12}") Edited November 1, 2006 by crzftx
MrBeatnik Posted November 1, 2006 Posted November 1, 2006 (edited) Also, if the window exists, why would you wait for it to be active?If there is more than one window on the screen, they both exist, but only one has focus.Making it active ensures that it first has focus before proceeding.It's a good bit of code to have in when working with windows. Edited November 3, 2006 by MrBeatnik Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now