Sign in to follow this  
Followers 0
JohnOne

@ScriptName [Solved]

13 posts in this topic

#1 ·  Posted (edited)

I observed some odd behaviour, and just wondering why this happens? and if Im doing something wrong.

If @ScriptName = "Test.au3" Then
    ConsoleWrite(@ScriptName & @CRLF) ;writes "Test.au3"
EndIf

If Not @ScriptName = "Tess.au3" Then
    ConsoleWrite("Wrong" & @CRLF) ;does not write "wrong"
EndIf

I also tried

$sName = @ScriptName
If $sName = "Test.au3" Then
    ConsoleWrite(@ScriptName & @CRLF) ;writes "Test.au3"
EndIf

If Not $sName = "Tess.au3" Then
    ConsoleWrite("Wrong" & @CRLF) ;does not write "wrong"
EndIf

With the same result

EDIT: sorry, I guess "Not" only works with boolean type. :idea:

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites



Try this one :idea:

If @ScriptName = "Test.au3" Then
    ConsoleWrite(@ScriptName & @CRLF) ;writes "Test.au3"
EndIf

If Not (@ScriptName = "Tess.au3") Then
    ConsoleWrite("Wrong" & @CRLF) ;does not write "wrong"
EndIf

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

too late :idea:

Share this post


Link to post
Share on other sites

Glad to be of service!


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

#7 ·  Posted (edited)

whatever Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Nope. Not a bad point of view. But "Not $a=$b" => "(Not $a)=$b"

Now Im a little more confused, I came to the conclusion that autoit internally converts the value to boolean type if it is not already of that type.

The following confirmed it (for me anyway)

$100 = 100
$text ="text"
$not100 = (Not $100)
$Nottext = (Not $text)

ConsoleWrite($not100 & @CRLF & $Nottext & @CRLF)

Output

False

False

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

whatever Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

autoit DOES convert to a boolean value but the problem was the order of operations.

If Not @ScriptName = "Tess.au3" Then

is the same as

If (Not @ScriptName) = "Tess.au3" Then

because the Not applies 1st. Since the @ScriptName is a string that when converted to Boolean is True (any non-zero or non-empty string is True)

This basically evaluated to

If Not True = "Tess.au3" Then

then

If Not True = True Then

in other words

If False = True Then

When you change the order of operations by saying

If Not (@ScriptName = "Tess.au3") Then

the strings are compared first. Since they are false the operation becomes

If Not (False) Then

which of course is

If True Then
Edited by ShawnW

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

whatever Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

autoit DOES convert to a boolean value but the problem was the order of operations.

Great post!

Edited by notsure

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