Sign in to follow this  
Followers 0
ts29

Can i put two conditions in IF?

11 posts in this topic

#1 ·  Posted (edited)

$state = WinGetState($hWnd)
    If BitAnd( $state, 1) AND ( $state, 2) AND ( $state, 4) Then
        blablabla

Is this do-able? Because when i do this code, i get unexpected behaviour in that even if the window is not visible and also not enabled( 2 and 4, 1 is whether window exists), the program scans the desktop as a "client" instead and returns maximum negative values on the integer coordinates (-32000,-32000).

I did search the Help File for If.. Then.. Else Conditional Statements but i did not find anything

Edited by ts29

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

$state = WinGetState($hWnd)

If $state = 2+4+8+16 Then
    ;dooo stuffff
    
EndIf

You need to add up the values from WinGetState

1 = Window exists

2 = Window is visible ; ----

4 = Window is enabled ; ----

8 = Window is active ; ----

16 = Window is minimized

32 = Window is maximized ; ----

but any other if statment is like this..

If $var1 = "a" & $var2 = "a" & $var3 = "a" Then
Edited by Steveiwonder

They call me MrRegExpMan

Share this post


Link to post
Share on other sites

Ahh thanks a lot. I shall go and try it out and tell you guys how it goes.

Share this post


Link to post
Share on other sites

Forgive me if I'm wrong, but in C++ you can use || for or. So if any of the conditions are true, code will be executed. But with and, all conditions must be met.

In C or C++ you use || for Logical Or and | for Bitwise Or.

Steviewonder has given a not-to-be-followed example by using addition to combine styles; styles and many other values should be Ored to get the result otherwise things can go wrong. For example BitOr(7,1) is not the same as 7 + 1.

You misunderstood his example of using &. In AutoIt the & operator is not for a logical And operation but for string concatenation. In AutoIt

7 & 1

will produce the string "71" from the 2 numbers.

@ ts29

Your example should be like this

$state = WinGetState($hWnd)
 If BitAnd( $state, 1) AND BitAnd( $state, 2) AND BitAnd( $state, 4) Then
 blablabla

or

If BitAnd( $state, BitOr(1,2,4)) then

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

In C or C++ you use || for Logical Or and | for Bitwise Or.

Steviewonder has given a not-to-be-followed example by using addition to combine styles; styles and many other values should be Ored to get the result otherwise things can go wrong. For example BitOr(7,1) is not the same as 7 + 1.

You misunderstood his example of using &. In AutoIt the & operator is not for a logical And operation but for string concatenation. In AutoIt

7 & 1

will produce the string "71" from the 2 numbers.

@ ts29

Your example should be like this

$state = WinGetState($hWnd)
 If BitAnd( $state, 1) AND BitAnd( $state, 2) AND BitAnd( $state, 4) Then
 blablabla

or

If BitAnd( $state, BitOr(1,2,4)) then

Ahh thank you. Although i used the example of

If $state = 1+2+4 Then

Thank you for that very elegant code though.

Share this post


Link to post
Share on other sites

Ahh thank you. Although i used the example of

If $state = 1+2+4 Then

I think you must have missunderstood what martin was saying.

Share this post


Link to post
Share on other sites

.. i used the example of

If $state = 1+2+4 Then

and if the window is Active the test will fail.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

and if the window is Active the test will fail.

Ah, yes, but when i click on the exe on the desktop, the window is visible, maximized, but greyed out and inactive. So it's exactly what I need. Thank you though.

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