tonycst

Help me understand operators

8 posts in this topic

#1 ·  Posted (edited)

If WinActivate($LabelWindow) <> 0 Then
Exit
Endif

Since WinActivate returns handle, will my If statement  Exit if window does exist ?

If window does not exist, return is 0, so if i understand correctly, less or more 0 is what i need to exit once any handle is present, correct ?

 

If so, does <=> would mean Less or equal or more then 0 rendering it useless since all 3 operators are against each other ?

For example
If WinActivate($LabelWindow) <> 0 Then
Exit
Endif

This will exit no matter what, correct ?
Thanks !

Edited by tonycst

Share this post


Link to post
Share on other sites



#2 ·  Posted

Using <=> would cause an error because that operator doesn't exist in AutoIt. I'm not really sure how that would even work in the real world because everything would match it. Your two examples are the same, so not sure what you're asking with the last part.

To answer the first question, it won't exit until the window exists or can be activated.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks.

Could the <> 0 be replaced with "Not 0" ? How would that look like and is it only for strings ?

Edited by tonycst

Share this post


Link to post
Share on other sites

#4 ·  Posted

1 hour ago, tonycst said:

Thanks.

Could the <> 0 be replaced with "Not 0" ? How would that look like and is it only for strings ?

@tonycst you could probably test that yourself faster than you could post . Take a look at the help file for Not.


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

Share this post


Link to post
Share on other sites

#5 ·  Posted

I did. I cant make much sense of it how to use Not.

Thats why i ask.

Can u give me one or two very simple examples with Not use in an If statement ?

Share this post


Link to post
Share on other sites

#6 ·  Posted

In simplest form, you should enclose the statement when using Not, something like this:

$var = "b"

If Not ($var = "n") Then
    ConsoleWrite("Wrong, $var = " & $var & @CRLF)
Else
    ConsoleWrite("Right!" & @CRLF)
EndIf

This would be the equivalent of :

If $var <> "n" Then

 


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

Share this post


Link to post
Share on other sites

#7 ·  Posted

Simply put, Not takes an expression, converts it into a boolean value (true/false) and inverts it. So Not (1 = 1) will be evaluated to False


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

When it comes to NOT look at it this way.

Something can be in 3 states - True, False or Not Set. On, Off or Not Set.

To give a more expanded example, look at the simple MsgBox function, where you use Yes, No, Cancel. You might want something to occur when either YES or NO is clicked, but not when CANCEL is clicked.
 

$ans = MsgBox(262195, "Query", "YES = Clear & Start. NO = Start. CANCEL = Abort.")
If NOT $ans = 2 Then
    If $ans = 6 Then $val = ""
    Run("Notepad.exe")
Else
    Exit
EndIf

Of course, you could also just simply use - If $ans <> 2 Then

It is perhaps most commonly used for - If NOT @error Then

@error could be one of many values.

Of course, the proper way (most economical anyway) of doing the MsgBox, would be as follows.

$ans = MsgBox(262195, "Query", "YES = Clear & Start. NO = Start. CANCEL = Abort.")
If $ans = 2 Then
    Exit
Else
    If $ans = 6 Then $val = ""
    Run("Notepad.exe")
EndIf

Which saves on typing.

Edited by TheSaint

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

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