Jump to content

"If" statement has Issue


Recommended Posts

Ok here I go:

1 Opt ("TrayIconDebug", 1)

2 Run ("C:\Program Files\SecureCRT\SecureCRT.EXE")
    [color="#FF0000"]3 If WinWaitActive ("SecureCRT", "This is the first time")[/color] Then 
        4 Sleep (1000)
        5 ControlClick("SecureCRT", "OK", 1)
        6 If WinWaitActive("SecureCRT", "License Agreement") Then
            7 Sleep (1000)
            8 ControlClick("SecureCRT", "I Agree", 1)
            9 WinWaitActive("Quick Connect", "&Protocol:")
            10 Sleep (1000)
            11 ControlClick ("Quick Connect", "Cancel", 2)
        12 ElseIf WinWaitActive ("SecureCRT", "This evaluation copy") Then
            13 Sleep (750)
            14 Send ("!e")
        15 EndIf
    16 EndIf
        
    17 If WinWaitActive ("SecureCRT", "This evaluation copy") Then
        Sleep (750)
        Send ("!e")     
    EndIf

    If WinWaitActive("SecureCRT", "License Agreement") Then
            Sleep (1000)
            ControlClick("SecureCRT", "I Agree", 1)
            WinWaitActive("Quick Connect", "&Protocol:")
            Sleep (1000)
            ControlClick ("Quick Connect", "Cancel", 2)
    EndIf

Don't be afraid by my advanced coding. I'm sure you'll figure it out. :)

So when I execute the script, I get this screen:

Posted Image

with Window Info:

Posted Image

and it got stuck at line 3 in red. Why don't I just ignore line 3 - 16 and start with line 17? It's because when I do a fresh install, I'm required to go through the prompt which is why I wrote line 3 - 16. However, during testing, instead of doing a fresh install everytime, I just execute the program using this script and it would however stopped at line 3 (WinWaitActive ("SecureCRT", "This is the first time")). Remember, since it is not a fresh install, so line 3-16 is irrelevant. What it should have done is skip the "IF" statement since it is no longer true according to picture 1 after executing the program SecureCRT and jump to line 17. Anyone has any idea to why it stopped? I tried to be as specific as I can, but if there are any other confusion, please let me know.

Thanks guys! :">

Link to comment
Share on other sites

Don't use WinWaitActive, you're basically telling it to wait until that window shows up. Use WinActive instead.

[font="Verdana"]People who say it cannot be done should not interrupt those who are doing it. - George Benard Shaw[/font]

Link to comment
Share on other sites

Thanks for the quick reply.

Doing what you said I changed my scrip to:

Opt ("TrayIconDebug", 1)

Run ("C:\Program Files\SecureCRT\SecureCRT.EXE")
    If WinActive ("SecureCRT", "This is the first time") Then 
        Sleep (1000)
        ControlClick("SecureCRT", "OK", 1)
        If WinWaitActive("SecureCRT", "License Agreement") Then
            Sleep (1000)
            ControlClick("SecureCRT", "I Agree", 1)
            WinWaitActive("Quick Connect", "&Protocol:")
            Sleep (1000)
            ControlClick ("Quick Connect", "Cancel", 2)
        ElseIf WinWaitActive ("SecureCRT", "This evaluation copy") Then
            Sleep (750)
            Send ("!e")
        EndIf
    EndIf
        
    If WinActive ("SecureCRT", "This evaluation copy") Then
        Sleep (750)
        Send ("!e")     
    EndIf

    If WinActive("SecureCRT", "License Agreement") Then
            Sleep (1000)
            ControlClick("SecureCRT", "I Agree", 1)
            WinWaitActive("Quick Connect", "&Protocol:")
            Sleep (1000)
            ControlClick ("Quick Connect", "Cancel", 2)
    EndIf

It worked better than before knowing that the if statement is working, however, it ignored all the if loops. I figure, it couldn't find the screen that it's looking for. So to be exact, I execute the script, the program ran and got stuck at the image below, while I checked AutoIT Debugger, it ran through all the IF statements (like it's all false):

Posted Image

Basically back at line 3 again.

Link to comment
Share on other sites

Try putting in Sleep(1000) after the Run to give it some time to start before proceeding.

Or else try adding in a WinWait situation, that will pause the script until the window pops up. It could be that it is looking for the window before it has a chance to pop up.

Good luck! Have to take off. But take a look at and play around with WinWait, you can build an If statement with that so it could look for either window (from fresh install or otherwise).

[font="Verdana"]People who say it cannot be done should not interrupt those who are doing it. - George Benard Shaw[/font]

Link to comment
Share on other sites

I think you are checking for the windows too quickly after the Run(). Try it like this:

Opt("TrayIconDebug", 1)

Run("C:\Program Files\SecureCRT\SecureCRT.EXE")
If WinWait("SecureCRT", "", 10) Then
    WinActivate("SecureCRT", "")
    
    If WinActive("SecureCRT", "This is the first time") Then
        Sleep(1000)
        ControlClick("SecureCRT", "OK", 1)
        If WinWaitActive("SecureCRT", "License Agreement") Then
            Sleep(1000)
            ControlClick("SecureCRT", "I Agree", 1)
            WinWaitActive("Quick Connect", "&Protocol:")
            Sleep(1000)
            ControlClick("Quick Connect", "Cancel", 2)
        ElseIf WinWaitActive("SecureCRT", "This evaluation copy") Then
            Sleep(750)
            Send("!e")
        EndIf
    EndIf

    If WinActive("SecureCRT", "This evaluation copy") Then
        Sleep(750)
        Send("!e")
    EndIf

    If WinActive("SecureCRT", "License Agreement") Then
        Sleep(1000)
        ControlClick("SecureCRT", "I Agree", 1)
        WinWaitActive("Quick Connect", "&Protocol:")
        Sleep(1000)
        ControlClick("Quick Connect", "Cancel", 2)
    EndIf
Else
    MsgBox(16, "Error", "SecureCRT did not open before timeout!")
    Exit
EndIf

:)

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
Link to comment
Share on other sites

Thanks guys. I know i'm being spoiled with your help and i really appreciate it.

Mind telling me why WinWaitActive ("SecureCRT", "") wouldn't work and that I have to use WinWait and set time out? I mean using WinWait would work with my system, but what if it passes 10 seconds on another PC to load? In my logical opinion, wouldn't it be easier just using WinWaitActive?

Just curious as this is a new adventure. :)

Dreamzboy

Link to comment
Share on other sites

Mind telling me why WinWaitActive ("SecureCRT", "") wouldn't work and that I have to use WinWait and set time out? I mean using WinWait would work with my system, but what if it passes 10 seconds on another PC to load? In my logical opinion, wouldn't it be easier just using WinWaitActive?

think so..

Link to comment
Share on other sites

Mind telling me why WinWaitActive ("SecureCRT", "") wouldn't work and that I have to use WinWait and set time out? I mean using WinWait would work with my system, but what if it passes 10 seconds on another PC to load? In my logical opinion, wouldn't it be easier just using WinWaitActive?

That would work, but would never timeout or pop an error if something went wrong with the Run(). The intention was to make sure the program started up normally before going on, and to have some error handling if it didn't. If 10 seconds is too short, make it 20, or 30, or 120, whatever...

The problem with the script I changed to generate that one (from post #3) was it DIDN'T use WinWait() or WinWaitActive(). It did three IF's with just WinActive() -- notice the lack of WAIT! All three IF's were done in a milisecond or two after the Run(). Probably way too fast for the program to have loaded from disk and generated any of the windows yet.

:)

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
Link to comment
Share on other sites

Thanks guys. I know i'm being spoiled with your help and i really appreciate it.

Mind telling me why WinWaitActive ("SecureCRT", "") wouldn't work and that I have to use WinWait and set time out? I mean using WinWait would work with my system, but what if it passes 10 seconds on another PC to load? In my logical opinion, wouldn't it be easier just using WinWaitActive?

Just curious as this is a new adventure. :)

Dreamzboy

I had similar problems.

Instead

WinWaitActive("Title")oÝ÷ جyÖ®¶­sevåvBgV÷CµFFÆRgV÷C²¥våvD7FfRgV÷CµFFÆRgV÷C²
Link to comment
Share on other sites

I have never had much luck with WinWaitActive. I always use WinWait. Unless there would be a situation where during the install the windows might come up in a different order I would stick with WinWait.

I have never written an install script that uses If/Then since all of my installs (so far) have been clean installs, not reinstalls. I would try using WinWaitActive only after the If and for the remainder of that If statement, use WinWait with some control clicks or Send().

Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]

Link to comment
Share on other sites

That would work, but would never timeout or pop an error if something went wrong with the Run(). The intention was to make sure the program started up normally before going on, and to have some error handling if it didn't. If 10 seconds is too short, make it 20, or 30, or 120, whatever...

The problem with the script I changed to generate that one (from post #3) was it DIDN'T use WinWait() or WinWaitActive(). It did three IF's with just WinActive() -- notice the lack of WAIT! All three IF's were done in a milisecond or two after the Run(). Probably way too fast for the program to have loaded from disk and generated any of the windows yet.

:)

Not that I have anything against your method, your method works great! My point was simply why wait an additional 20 seconds when the program is loaded and ready to run. But for the stability sake, I think it's the only way.

With your code, it got pass the first if but it doesn't seem to run the

ElseIf WinWaitActive("SecureCRT", "This evaluation copy") Then
            Sleep(750)
            Send("!e")
      EndIf

I think it has something to do with WinWaitActive again, but I'll figure out from here. Thanks for shinning the light.

Link to comment
Share on other sites

WinWaitActive has a timeout option too, so I don't see what's wrong with using it.

It won't go into endless loop if you set timeout.

Edited by Siao

"be smart, drink your wine"

Link to comment
Share on other sites

Another suggestion:

Don't use full titles until you need so.

Put the option

Opt("WinTitleMatchMode", 2)

and use only a significant part of the window title (enough to identify it).

I had myself a couple of problems with WinWaitActive and I've solved them by shortening titles and text.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Not that I have anything against your method, your method works great! My point was simply why wait an additional 20 seconds when the program is loaded and ready to run. But for the stability sake, I think it's the only way.

With your code, it got pass the first if but it doesn't seem to run the

ElseIf WinWaitActive("SecureCRT", "This evaluation copy") Then
            Sleep(750)
            Send("!e")
      EndIf

I think it has something to do with WinWaitActive again, but I'll figure out from here. Thanks for shinning the light.

Just to be clear, the various "Wait" functions check for the condition about every 250ms. If you use a 20sec timeout, for example, and the window appears after 5 seconds, the script will continue within 250ms after that. It will NOT continue to wait for the rest of the 20sec. The timeout just lets you programatically deal with the possibility that the window NEVER appears (or becomes active, etc.).

You seemed to be under the misconception that it would continue to wait for the remainder of the timeout.

Cheers!

:)

Edited by PsaltyDS
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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...