Jump to content

If.. Else.. statement don't work.


Recommended Posts

Right of the top, I'm totally n00b at this.

This is a script to maximize Mailwasher if it is in the tray, or else close it to tray. It closes it perfectly, but I can't get it to open up.

If I make a script with just the Else statement, it works like a charm to, but together they don't work.

Anyway, here is my simple code:

If WinExists("MailWasher") Then
    WinClose("MailWasher")
Else 
    Send( "!+m" )
EndIf

Any good ideas on how to make this work properly?

(Alt+Shit+m is a shortcut in MailWasher to maximize it.)

Edited by tristan208
Link to comment
Share on other sites

The WinClose() function does not maximize a window. It actually closes it (terminating the program in most cases). What you want is

WinSetState("MailWasher", "", @SW_MAXIMIZE)

That will maximize the window if that program is open.

I think you misunderstood me. It's usually minimized to tray, and I want it to maximize from tray, but only if it isn't maximized. If it is maximized I want it to close. Split up these two statements work a charm, but combined in an If.. Else.. I can't get it to work.

Link to comment
Share on other sites

Right of the top, I'm totally n00b at this.

This is a script to maximize Mailwasher if it is in the tray, or else close it to tray. It closes it perfectly, but I can't get it to open up.

If I make a script with just the Else statement, it works like a charm to, but together they don't work.

Anyway, here is my simple code:

If WinExists("MailWasher") Then
    WinClose("MailWasher")
Else 
    Send( "!+m" )
EndIf

Any good ideas on how to make this work properly?

(Alt+Shit+m is a shortcut in MailWasher to maximize it.)

Because if the window exists then you are closing it.

All you should need is

If WinExists("MailWasher") AND WinGetState("MailWasher") < 32 Then WinSetState("MailWasher", "", @SW_Maximize)

Also make sure that you have looked at Opt ("WinTitleMatchMode") and the special information about Win Titles in the help file.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

George, what is "< 32", I don't understand it.

It means if the state of the window is less than (<) 32.

From the help file for WinGetState()

32 = Window is maximized

So what we are saying here is if the Window is not Maximized then Maximize it.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I'm obviously not very good at explaining my needs, because it seems like you all misunderstood me.

MailWasher always resides in the tray, and when new mail arrives it starts blinking. What I want is the possibility

to open it up from the tray, which can easily be done by pressing shift+alt+m. But if the Mailwasher window is already

open, I want the script to close it back to tray.

The reason for this, is that I have a 'Mail' button on my mouse, but MailWasher isn't supported by the mouse software,

so I wanted to write my own little thing to get the job done.

And now I'm confused.

The first part of the statement checks if MailWasher exists, and if it does, it closes it to tray. And that works.

But if MailWasher doesn't exist, shouldn't it run the Else statement?

Edited by tristan208
Link to comment
Share on other sites

I'm obviously not very good at explaining my needs, because it seems like you all misunderstood me.

MailWasher always resides in the tray, and when new mail arrives it starts blinking. What I want is the possibility

to open it up from the tray, which can easily be done by pressing shift+alt+m. But if the Mailwasher window is already

open, I want the script to close it back to tray.

The reason for this, is that I have a 'Mail' button on my mouse, but MailWasher isn't supported by the mouse software,

so I wanted to write my own little thing to get the job done.

Try this but I'm just going off the top of my head here and it's already been pointed out that my memory is not great.

If WinExists("MailWasher") Then
   If NOT WinGetState("MailWasher") >= 32 Then
      WinSetState("MailWasher", "", @SW_Maximize);; You could use your send instead if you really insist.
   Else
      WinClose("MailWasher");;  Watch out that this doesn't exit MailWasher entirely.  If it does, I have a func to fix it.
   EndIf
EndIf

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Try this but I'm just going off the top of my head here and it's already been pointed out that my memory is not great.

If WinExists("MailWasher") Then
   If NOT WinGetState("MailWasher") >= 32 Then
      WinSetState("MailWasher", "", @SW_Maximize);; You could use your send instead if you really insist.
   Else
      WinClose("MailWasher");;  Watch out that this doesn't exit MailWasher entirely.  If it does, I have a func to fix it.
   EndIf
EndIf

Just tried your code, it didn't work.

I can't get it to open up from tray, unless I put the Send at the very beginning.

The WinSetState doesn't work when MailWasher is in the tray, that's why I want the Send to send the shortcut to MailWasher.

And I don't want it to close entirely, just put it back to the tray. (This part works flawlesly.)

Edited by tristan208
Link to comment
Share on other sites

My guess is that when the window is closed, it just hides itself, it doesn't destroy the window, therefore your first if statement is always true.

Edit:

Therefore your original code should be:

If WinExists("MailWasher") And BitAND(WinGetState("MailWasher"), 2) Then
    WinClose("MailWasher")
Else
    Send( "!+m" )
EndIf
Edited by FreeFry
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...