Jump to content
rudi

Help file, language reference, operators

Recommended Posts

Hi.

for the "==" operator the language reference is telling:

Tests if two strings are equal. Case-sensitive. The left and right values are converted to strings if they are not strings already. This operator should only be used if string comparisons need to be case-sensitive.

 

This operator "==" can also be used to check, if a value is really "true" or just not 0 / false:

 

; Autoit v 3.3.14.5

Dim $aValues[9] = [True, False, "Just-some-string",-2,-1,0,1,2,100]

For $CheckThis In $aValues
    ConsoleWrite("-------------- " & $CheckThis & " ----------------" & @CRLF)
    If $CheckThis = True Then
        ConsoleWrite("It's true, when using one ""="" doing the compare." & @CRLF)
        If $CheckThis == True Then
            ConsoleWrite("still true, when using two ""=="" doing the compare." & @CRLF)
        Else
            ConsoleWrite("It's *NO MORE* true, when using two ""=="" doing the compare!" & @CRLF)
        EndIf
    Else
        ConsoleWrite("It's *NOT* true" & @CRLF)
    EndIf
Next
-------------- True ----------------
It's true, when using one "=" doing the compare.
still true, when using two "==" doing the compare.
-------------- False ----------------
It's *NOT* true
-------------- Just-some-string ----------------
It's true, when using one "=" doing the compare.
It's *NO MORE* true, when using two "==" doing the compare!
-------------- -2 ----------------
It's true, when using one "=" doing the compare.
It's *NO MORE* true, when using two "==" doing the compare!
-------------- -1 ----------------
It's true, when using one "=" doing the compare.
It's *NO MORE* true, when using two "==" doing the compare!
-------------- 0 ----------------
It's *NOT* true
-------------- 1 ----------------
It's true, when using one "=" doing the compare.
It's *NO MORE* true, when using two "==" doing the compare!
-------------- 2 ----------------
It's true, when using one "=" doing the compare.
It's *NO MORE* true, when using two "==" doing the compare!
-------------- 100 ----------------
It's true, when using one "=" doing the compare.
It's *NO MORE* true, when using two "==" doing the compare!

 

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

From my personal view, it comes from other other programming languages.  Most novice programmers don't bother to look at those simplest operations, they put codes together and if it works without error, it must be right...

Share this post


Link to post
Share on other sites

IMHO precise documentation is always a very valuable thing.

 

To be able to tell if a result value is really TRUE or just "not zero" might be helpful. Not much extra text, pointing out the difference clearly.

Tests if two strings are equal. Case-sensitive. The left and right values are converted to strings if they are not strings already. This operator should only be used if string comparisons need to be case-sensitive. Testing boolean with "$Value == TRUE" will only match, if the $Value really is TRUE, not just different from FALSE / 0, as "=" does.

Never mind, just my 2 cent 😉


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites
Posted (edited)
34 minutes ago, rudi said:

Testing boolean with "$Value == TRUE" will only match, if the $Value really is TRUE,

This is a direct, obvious consequence of what's already stated just above in the help file as it is right now:

34 minutes ago, rudi said:

The left and right values are converted to strings if they are not strings already.

Assuming $value = (1 = 1), that is $value = True, we get:

VarGetType($Value) : 'Bool' which implies that it has to be converted to a string
String($Value) -> 'True'

Same for the boolean constant TRUE:
String(TRUE) -> 'True'

So your comparison boils down to:
'True' == 'True'
which is trivially True.

 

I don't see what's unclear in the current statement about ==

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...