Jump to content

Help me understand operators


Recommended Posts

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Moderators
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.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

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

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

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

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

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...