Jump to content

[Solved] Why is $a = $b


Recommended Posts

Do I missed something or why is $a = $b when $a="" and $b=0?

Local $a = ""
Local $b = 0

If $a = $b Then
    ConsoleWrite("equal!" & @CRLF)
Else
    ConsoleWrite("NOT equal!" & @CRLF)
EndIf

It seems to be that "" is set to 0 in the memory for variable $a...

BR,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

One is number the other is a string. It is not good practice to compare them.

You need to convert one to the other type - maybe like this:

$x = Number("3.14") ;returns 3.14

@Edit.

Strings beginning with letters are represented as 0 so:

Local $a = ""
Local $b = 0

If $a = String($b) Then
    ConsoleWrite("equal!" & @CRLF)
Else
    ConsoleWrite("NOT equal!" & @CRLF)
EndIf
Edited by Juvigy
Link to comment
Share on other sites

Same when line 1 is: Local $a

$a should be NUL and NUL should not be equal with 0 or?

BR,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

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

Link to comment
Share on other sites

(re)read Help page "Language Reference - Datatypes" (for starters)

It should clearup a lot should of initial or basic question about AutoIt variable handling/behavior. (strings, numbers and bools)

Good hint:

...If a string is used as a boolean and it is an empty string "" , it will be assumed to equal False (see below). For example, NOT "" equals the Boolean true...

BR,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Good hint:

...If a string is used as a boolean and it is an empty string "" , it will be assumed to equal False (see below). For example, NOT "" equals the Boolean true...

Related, but not exactly what you were seeing in the OP.

You used a compare operator "=" with a numeric, so a numeric compare was done. AutoIt made an attempt to recast "" as a number first, and the empty string evaluated to 0 for that operation.

You could have forced string comparison with "==":

ConsoleWrite("Numeric:  " & ("" = 0) & @LF)
ConsoleWrite(" String:  " & ("" == 0) & @LF)

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

The problem occured when I used

...
    If IsObj($colItems) Then
        For $objItem In $colItems
            $NW_DNS3 = $objItem.DNSServerSearchOrder(2)
        Next
    EndIf
    Local $DNS3 = StringStripWS($NW_DNS3, 2)
    Local $chk_text = 0
    If $DNS3 = $chk_text Then
...

$NW_DNS3 was empty because no 3rd DNS search order was not entered but If case was always true!

Local $a or Local $a = "" is a string type -> "Only an empty string ("") will be a Boolean false"

and thus $a = 0 -> If 0 = 0 then is always the case!

Now it is clear to me! I changed $chk_text to "na" :mellow:

Thanks for your replies!

BR,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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