AutoHotkey Community

It is currently May 27th, 2012, 6:53 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: September 21st, 2011, 2:29 am 
Offline

Joined: August 4th, 2009, 3:58 am
Posts: 373
Hello,

What is the correct way to combine the following two If/Else scripts?
Code:
SetTitleMatchMode, 2
IfWinExist, Contacts
{
    WinActivate 
    return
}
else
{
    SetTitleMatchMode, 2
    WinActivate, Outlook
    return
}
SetTitleMatchMode, 2
IfWinExist, Inbox
{
    WinActivate 
    return
}
else
{
    SetTitleMatchMode, 2
    WinActivate, Outlook
    return
}
return
One of them by itself works fine but if I put them back to back, as shown above, only the first works.

Thanks

_________________
"A person who has never made a mistake is a person who has never tried anything new." ~Albert Einstein
"Any fool can make things larger and more complex. It takes a touch of genius...to move in the opposite direction." ~Albert Einstein


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 21st, 2011, 4:11 am 
Offline

Joined: April 12th, 2010, 7:27 am
Posts: 152
I'm no expert, but I think your problem is the returns. Try this instead:

Code:
SetTitleMatchMode, 2
IfWinExist, Contacts
    WinActivate 
else
{
    SetTitleMatchMode, 2
    WinActivate, Outlook
}
SetTitleMatchMode, 2
IfWinExist, Inbox
    WinActivate 
else
{
    SetTitleMatchMode, 2
    WinActivate, Outlook
}
return


Also, looking through this, after the first else is a SetTitleMatchMode, 2. So regardless of the if/else it's going to run that command... So this might be even better:

Code:
SetTitleMatchMode, 2
IfWinExist, Contacts
    WinActivate 
else
    WinActivate, Outlook
SetTitleMatchMode, 2
IfWinExist, Inbox
    WinActivate 
else
{
    SetTitleMatchMode, 2
    WinActivate, Outlook
}
return
[/code]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 22nd, 2011, 1:42 pm 
Offline

Joined: January 15th, 2008, 1:46 pm
Posts: 28
Or try this:

Code:
SetTitleMatchMode, 2

IfWinExist, Inbox
   WinActivate
else IfWinExist, Contacts
   WinActivate
else
   WinActivate, Outlook
Return


Report this post
Top
 Profile  
Reply with quote  
PostPosted: September 23rd, 2011, 8:19 am 
Online
User avatar

Joined: December 20th, 2004, 12:19 pm
Posts: 798
Location: LooseChange911.com Ask Questions, Demand Answers █ The WTC bldgs █ shouldn't have fallen █ that fast
OK, since no one replied with the code I'd use, I'll do it...

Code:
SetTitleMatchMode, 2

if (WinExist("Contacts") || WinExist("Inbox")) {
   WinActivate   
} else {
   WinActivate, Outlook
}
return

...or possibly...

Code:
SetTitleMatchMode, 2

GroupAdd, Outlook_Subwindow, Contacts
GroupAdd, Outlook_Subwindow, Inbox

if (WinExist("ahk_group Outlook_Subwindow")) {
   WinActivate
} else {
   WinActivate, Outlook
}
return

...note that the 2nd code is not a 100% exact reimplementation of the 1st code (there could be cases where they would do different things), so the 1st code may be the best option.

_________________
AutoHotkey-Hotstring.ahk - Helping the world spell "AutoHotkey" correctly! (btw, it's a lowercase k!)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], migz99, sjc1000, Yahoo [Bot] and 67 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group