Sign in to follow this  
Followers 0
LovelyJane

Problem with Select... Case

5 posts in this topic

Hi, I am trying to have AutoIt activate whichever window of either one type, that I have currently opened, example: I have FF opened but IE and GC is closed, so I want FF window to be activated however I am not sure how to go about with this.

IE = Windows Internet Explorer, GC = Google Chrome and FF = Mozilla Firefox

Local $titleIE2 = String("AutoIt Forums - Windows Internet Explorer")
Local $titleGC2 = String("AutoIt Forums - Google Chrome")
Local $titleFF2 = String("AutoIt Forums - Mozilla Firefox")

Func ActivateWindow2()
    Select
        Case $titleIE2
            WinWait($titleIE2,"")
            If Not WinActive($titleIE2,"") Then WinActivate($titleIE2,"")
            WinWaitActive($titleIE2,"")
        Case $titleGC2
            WinWait($titleGC2,"")
            If Not WinActive($titleGC2,"") Then WinActivate($titleGC2,"")
            WinWaitActive($titleGC2,"")
        Case $titleFF2
            WinWait($titleFF2,"")
            If Not WinActive($titleFF2,"") Then WinActivate($titleFF2,"")
            WinWaitActive($titleFF2,"")
        Case Else
            Exit
    EndSelect
EndFunc

Call ("ActivateWindow2")

Share this post


Link to post
Share on other sites



Is the current script failing or erroring out? I don't have the ability to duplicate your environment, so let us know what is, or is not happening and we will do our best.


C0d3 is P0etry( ͡° ͜ʖ ͡°)

Share this post


Link to post
Share on other sites

Why go through all that mess, when you're simply doing a WinActivate off the title? Why not just:

While 1
    If WinExists("AutoIt Forums -", "") Then WinActivate("AutoIt Forums -", "")
    Sleep(100)
WEnd
1 person likes this

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Oh, I am sorry, did not realize about WinExists, its my first time trying this with different window titles, thank you JLogan3o13.

Decided to go with:

Local $titleTest = String("AutoIt Forums -")

Func ActivateWindow2()
    If WinExists($titleTest, "") Then WinActivate($titleTest, "")
    WinWaitActive($titleTest,"")
EndFunc

Call ("ActivateWindow2")

I assume While... WEnd is a "always on" code?

Hence the Sleep(100) to not make the CPU usage into high usage?

Edited by LovelyJane

Share this post


Link to post
Share on other sites

Correct


√-1 2^3 ∑ π, and it was delicious!

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