Jump to content

If And Or


LuigiBem
 Share

Go to solution Solved by LuigiBem,

Recommended Posts

  • Developers

 

This is not a game.
This guy also wanted to know but I don't see the answer: :x
 
;This works
If $fpath = "..\Quest" Or $wrt[1] = 0 Then $TurnIt = "Nope"


;Why doesn't this
If $fpath = "..\Quest" And $wrt[1] = 0 Then $TurnIt = "Nope"

It's another one of those things not in Help. :bye:

 

 

So what is your problem as they are 2 different tests?

What are you expecting?

Post something that really shows your issue instead of  a few lines that don't have any meaning.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

First example needs only one of the camparisons to be true. For the second example both need to be true.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

LuigiBern,

It works for for me: :)

; Both match
$fPath = "..\Quest"
Global $wrt[2] = [0, 0]
$TurnIt_1 = "Yep!"
$TurnIt_2 = "Yep!"

If $fpath = "..\Quest" Or $wrt[1] = 0 Then $TurnIt_1 = "Nope"
If $fpath = "..\Quest" And $wrt[1] = 0 Then $TurnIt_2 = "Nope"

ConsoleWrite("Both match: " & $TurnIt_1 & " - " & $TurnIt_2 & @CRLF)

; Path matches
$fPath = "..\Quest"
Global $wrt[2] = [0, 1]
$TurnIt_1 = "Yep!"
$TurnIt_2 = "Yep!"

If $fpath = "..\Quest" Or $wrt[1] = 0 Then $TurnIt_1 = "Nope"
If $fpath = "..\Quest" And $wrt[1] = 0 Then $TurnIt_2 = "Nope"

ConsoleWrite("Path matches: " & $TurnIt_1 & " - " & $TurnIt_2 & @CRLF)

; wrt matches
$fPath = "..\Quest0"
Global $wrt[2] = [0, 0]
$TurnIt_1 = "Yep!"
$TurnIt_2 = "Yep!"

If $fpath = "..\Quest" Or $wrt[1] = 0 Then $TurnIt_1 = "Nope"
If $fpath = "..\Quest" And $wrt[1] = 0 Then $TurnIt_2 = "Nope"

ConsoleWrite("wrt matches: " & $TurnIt_1 & " - " & $TurnIt_2 & @CRLF)

; Neither match
$fPath = "..\Quest0"
Global $wrt[2] = [0, 1]
$TurnIt_1 = "Yep!"
$TurnIt_2 = "Yep!"

If $fpath = "..\Quest" Or $wrt[1] = 0 Then $TurnIt_1 = "Nope"
If $fpath = "..\Quest" And $wrt[1] = 0 Then $TurnIt_2 = "Nope"

ConsoleWrite("Neither match: " & $TurnIt_1 & " - " & $TurnIt_2 & @CRLF)
Why do you think it does not? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I will not refute my ingnorance here. I have no idea how this works. I expected the "And" to work the same as the "Or". I was hoping I could use the "Nope" as a variable later, but the script terminates.

The conditions match but the MsgBox comes back empty.

MsgBox(0, "$fpath", $fpath) ;This tests "..\Quest"
MsgBox(0, $wrt[1], $wrt[1]) ;This "0"
If $fpath = "..\Quest" And $wrt[1] = 0 Then $TurnIt = "Nope"
MsgBox(0, $TurnIt, $TurnIt)

I've tried all combinations of quotes: ($fpath = "..Quest") And ( the like...

Link to comment
Share on other sites

I expected the "And" to work the same as the "Or".

Why should it work the same way?

If you have a glass of beer AND a cup of coffe you have two beverages.

If you have a glass of beer OR a cup of coffe you have at least one beverage.

So And <> OR.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

LuigiBem.

Once again it works fine for me: :)

$fPath = "..\Quest"
Global $wrt[2] = [0, 0]
$TurnIt = "Yep!"

MsgBox(0, "$fpath", $fpath) ;This tests "..\Quest"
MsgBox(0, $wrt[1], $wrt[1]) ;This "0"
If $fpath = "..\Quest" And $wrt[1] = 0 Then $TurnIt = "Nope"
MsgBox(0, $TurnIt, $TurnIt)
I would recommend declaring $TurnIt before trying to access it as I have done above. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

My mistake. I expected it to work similar.  The "Or" continues on.  The "And" Terminates the Script.  The conditions seem to be met for both,  as far as I can tell, yet they are not working similarly as I see it.  I don't understand why $TurnIt does not fill the MsgBox with "Nope".

Link to comment
Share on other sites

  • Moderators

LuigiBem,

 

I don't understand why $TurnIt does not fill the MsgBox with "Nope".

Do you not see "Nope" when you run the script I posted immediately above? :huh:

 

The "Or" continues on. The "And" Terminates the Script

Not exactly. What happens is this:

; Here is the line with And
If condition_1 And condition_2 Then

; And needs both conditions to be true or it fails
If True And True Then   ; Both true and it works
If False And True Then  ; One false and it does not work - in fact AutoIt never even looks at the second condition
If True And False Then  ; One false and it does not work
If False And False Then ; Both false and it does not work - again AutoIt never even looks at the second condition

; Here is the line with Or
If condition_1 Or condition_2 Then

; Or needs only one of the two conditions to be true
If True And True Then   ; Both true and it works - AutoIt does not even look at the second condition
If False And True Then  ; One true and it works
If True And False Then  ; One true and it works - again AutoIt does not even look at the second condition
If False And False Then ; Both false and it does not work
I hope that makes it clearer. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Solution

$fPath = "..\Quest"

It turned out $fpath had a bug upstream which had caused me to question the difference between "And" & "Or".

You have made it very clear that I needed to look elsewhere for the bug.

Thank you very much for the explanation And Or understanding to resolve this issue.

Link to comment
Share on other sites

Why should it work the same way?

If you have a glass of beer AND a cup of coffe you have two beverages.

If you have a glass of beer OR a cup of coffe you only have one beverage.

So And <> OR.

 

Not exactly true... If you have a glass of beer OR a cup of coffee, all you know is that you didn't have no beverage.

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

Ops, you are correct.

Should be "at least one beverage" Somehow I had "Exclusive Or" in mind.

Fixed.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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