Sign in to follow this  
Followers 0
Neoborn

While Loop... = ( Problems

8 posts in this topic

#1 ·  Posted (edited)

Hey Guys,

It seems that I still don't ( noob ) fully understand the logic behind while, variables etc. I am becoming more familiar but still get a little confused because of the lack of experience.

I have a code here that should:

1. Opens SmartFTP

2. If the main window doesn't exist it checks for popup windows.

3. Closes popup windows

4. Exits.

My main problem is sometimes it doesn't catch one of the windows and also doesn't exit the loop for some reason.

What I want is the the program to just loop until "X" window exists then exit.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;   AutoIt Version:     3.1.0                                               ;
;   Author:             NeoBorn <neo_born@hotmail.com                       ;
;   Script Function:    Smart Launch and Close Information Box Tool.        ;
;øøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøø;

#NoTrayIcon

Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode
Opt("WinTitleMatchMode", 3)

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Function Calls~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
GoGoGadget()
ShutPop()
ByeBye()

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Functions~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
Func GoGoGadget()
    Run("E:\Program Files\SmartFTP\SmartFTP.exe", "E:\Program Files\SmartFTP\", @SW_SHOWDEFAULT)
EndFunc   ;==>GoGoGadget

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
Func ShutPop()
While 1
    If Not WinExists("SmartFTP v1.5 - Unlicensed") Then
        If WinExists("SmartFTP Expiration") = 1 Then
            If WinActive("SmartFTP Expiration") = 0 Then
                WinActivate("SmartFTP Expiration")
                    Send("{SPACE}")
            EndIf
        EndIf
    ElseIf Not WinExists("SmartFTP v1.5 - Unlicensed") Then
        If WinExists("SmartFTP License Reminder") = 1 Then
            If WinActive("SmartFTP License Reminder") = 0 Then
                WinActivate("SmartFTP License Reminder") 
                    Send("{SPACE}") 
                        Exit
            EndIf 
        EndIf
    EndIf
WEnd  
EndFunc   ;==>ShutPop

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
Func ByeBye()
    Exit
EndFunc   ;==>ByeBye

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;

Thanks for any help

:) Neoborn :(

Edited by Neoborn

~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Might try using Opt('WinTitleMatchMode', 2) (Sometimes there is an un-noticed space in the title)... Also, your ByeBye() function is never called because you never ExitLoop, you merely Exit.

Try this:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;   AutoIt Version:    3.1.0                        ;
;   Author:       NeoBorn <neo_born@hotmail.com      ;
;   Script Function:  Smart Launch and Close Information Box Tool.    ;
;øøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøø;

#NoTrayIcon

Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode
Opt("WinTitleMatchMode", 2)

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Function Calls~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
GoGoGadget()
ShutPop()

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Functions~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
Func GoGoGadget()
    Run("E:\Program Files\SmartFTP\SmartFTP.exe", "E:\Program Files\SmartFTP\", @SW_SHOWDEFAULT)
EndFunc   ;==>GoGoGadget

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
Func ShutPop()
    While 1
        If Not WinExists("SmartFTP v1.5 - Unlicensed") Then
            If WinExists("SmartFTP Expiration") Then
                If Not WinActive("SmartFTP Expiration") Then WinActivate("SmartFTP Expiration")
                Send("{SPACE}")
            ElseIf WinExists("SmartFTP License Reminder") Then
                If Not WinActive("SmartFTP License Reminder") Then WinActivate("SmartFTP License Reminder")
                Send("{SPACE}") 
                Exit
            EndIf
        EndIf
        Sleep(10)
    WEnd 
EndFunc   ;==>ShutPop
Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Nice, so that closes both popups but doesn't exit the script for some reason.

Can you also explain where I was going wrong with my code before?


~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Nice, so that closes both popups but doesn't exit the script for some reason.

Can you also explain where I was going wrong with my code before?

You had 2 If/ElseIf statements exactly the same, just look at my example and compare it to yours. You'll see I realized that you wanted to perform on action or the other if the Title didn't exist, your way would only ever perform the first action, because the ElseIf statement was never reached.

Edit:

Also you had "If WinActive = 0" etc... etc... meaning that it would only ever send Enter if the window wasn't active. What happens if it is active?

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

I don't think it's exiting because sometimes one of the popups doesn't appear and the program is still waiting for it. So I guess I could attempt to build in a time on the Else statement if neither appear after two to three seconds then just exit.


~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT

Share this post


Link to post
Share on other sites

Final working result

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;   AutoIt Version:     3.1.0                                               ;
;   Author:             NeoBorn <neo_born@hotmail.com                       ;
;   Script Function:    Smart Launch and Close Information Box Tool.        ;
;øøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøø;

#NoTrayIcon

Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode
Opt("WinTitleMatchMode", 2)

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Function Calls~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
GoGoGadget()
ShutPop()

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Functions~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
Func GoGoGadget()
    Run("E:\Program Files\SmartFTP\SmartFTP.exe", "E:\Program Files\SmartFTP\", @SW_SHOWDEFAULT)
    Sleep(500)
EndFunc   ;==>GoGoGadget

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
Func ShutPop()
    
    While 1
        If Not WinExists("SmartFTP v1.5 - Unlicensed") Then
            If WinExists("SmartFTP Expiration") Then
                If Not WinActive("SmartFTP Expiration") Then WinActivate("SmartFTP Expiration")
                Send("{SPACE}")
            ElseIf WinExists("SmartFTP License Reminder") Then
                If Not WinActive("SmartFTP License Reminder") Then WinActivate("SmartFTP License Reminder") 
                Send("{SPACE}") 
                Exit
            ElseIf Not WinExists("SmartFTP v1.5 - Unlicensed") Or WinExists("SmartFTP Expiration") Or WinExists("SmartFTP License Reminder") Then
                Exit
            EndIf
        EndIf
        Sleep(10)
    WEnd  
EndFunc   ;==>ShutPop

Thanks for all your help Smoke, I for one am happy your obsessed with these forums mr.FiftyPostsADay. :D

:) Neoborn :(


~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT

Share this post


Link to post
Share on other sites

Edit:

Also you had "If WinActive = 0" etc... etc... meaning that it would only ever send Enter if the window wasn't active. What happens if it is active?

LOL ....told yah I am teh nub :)


~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

LOL@50

Ok...

ElseIf Not WinExists("SmartFTP v1.5 - Unlicensed") Or WinExists("SmartFTP Expiration") Or WinExists("SmartFTP License Reminder") ThenoÝ÷ Ø*.Ð^jëh×6ElseoÝ÷ ØLZ^jëh×6Func ShutPop()
    While 1
        If Not WinExists("SmartFTP v1.5 - Unlicensed") Then
            If WinExists("SmartFTP Expiration") Then
                If Not WinActive("SmartFTP Expiration") Then WinActivate("SmartFTP Expiration")
                Send("{SPACE}") ; Do you want to exit after this send?
            ElseIf WinExists("SmartFTP License Reminder") Then
                If Not WinActive("SmartFTP License Reminder") Then WinActivate("SmartFTP License Reminder")
                Send("{SPACE}") 
                Exit
            Else
                Exit
            EndIf
        EndIf
       Sleep(10)
    WEnd 
EndFunc   ;==>ShutPop oÝ÷ ØGb´jë#fjË.)àÊrÛ°j{^vØb±«­¢+Ù±Í%9½Ð]¥¹á¥ÍÑÌ ÅÕ½ÐíMµÉÑQ@ØĸԴU¹±¥¹ÍÅÕ½Ðì¤=È9½Ð]¥¹á¥ÍÑÌ ÅÕ½ÐíMµÉÑQ@áÁ¥ÉÑ¥½¸ÅÕ½Ðì¤=È9½Ð]¥¹á¥ÍÑÌ ÅÕ½ÐíMµÉÑQ@1¥¹ÍIµ¥¹ÈÅÕ½Ðì¤Q¡
**Note the Not Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

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