LuigiBem

If And Or

12 posts in this topic

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:

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

 

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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...

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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".

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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.

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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