Sign in to follow this  
Followers 0
willw_magic

Script sometimes halts on "IF" statement

13 posts in this topic

#1 ·  Posted (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 by willw_magic

Share this post


Link to post
Share on other sites



Hmm, strange how your ControlClick has different text to your WinWait? :whistle:

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

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by willw_magic

Share this post


Link to post
Share on other sites

I only see 2 EndIfs and expect 3 of them. If you have tidy then run it to see errors.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.php

Hmm, hoping a missing EndIf was an easy cure :whistle: to your problem. I'm not sure now.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

#10 ·  Posted (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 by Hallman

Share this post


Link to post
Share on other sites

#11 ·  Posted (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 by crzftx

If I post a code or snippet, please tell me what I did wrong and/or what I can do better. Tell me my code/idea sucks, if it does. If I ask for help, refrain from only telling me to search the help file and/or the forums. I will search before asking, I just may not have searched with good keywords. If I say that I will look into something or fix something later, understand that I am most likely lying.

Share this post


Link to post
Share on other sites

#12 ·  Posted (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 by MrBeatnik

Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

Share this post


Link to post
Share on other sites

Thats why I added the "WinActivate" portion


If I post a code or snippet, please tell me what I did wrong and/or what I can do better. Tell me my code/idea sucks, if it does. If I ask for help, refrain from only telling me to search the help file and/or the forums. I will search before asking, I just may not have searched with good keywords. If I say that I will look into something or fix something later, understand that I am most likely lying.

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