Jump to content
Sign in to follow this  
Spiff59

Shouldn't this behavior be documented?

Recommended Posts

Spiff59

I couldn't find any posts regarding this, and there's nothing under "Language Reference - Operators"

Test(1,3,0,5)
;-------------------------------------------------
Func Test($a="",$b="",$c="",$d="",$e="",$f="")
Local $Parms[7] = [0, $a,$b,$c,$d,$e,$f]

For $i = 1 to 6
    If $Parms[$i] = "" Then ExitLoop
    $Parms[0] += 1
Next
MsgBox(1,"","Parms = " & $Parms[0])

$Parms[0] = 0
For $i = 1 to 6
    If $Parms[$i] == "" Then ExitLoop
    $Parms[0] += 1
Next
MsgBox(1,"","Parms = " & $Parms[0])
EndFunc;------------------------------------------

(There are more differences between the "=" and "==" operators than just case sensitivity)

Edited by Spiff59

Share this post


Link to post
Share on other sites
BrettF

Think of 0 being false. Which in a sense is also null. And since Autoit doesn't have data types, I kinda expect this...

And now comes a question, what is the outcome for this? Its obvious you are working on something, and well knowing the outcome can provide base for solutions... I could think of a few ways for a few different things, but I'm not sure how well they would go exactly...

EDIT:

A better way to explain what AutoIt perceives as true of false is like so:

Basically anything that is 0 or a blank string is false. True is everything else.

So we can do the following:

$d = 0

If $d = False Then
    MsgBox (0, "$d = 0", "$d is false!")
EndIf

$d = ""

If $d = False Then
    MsgBox (0, "$d = """"", "$d is false!")
EndIf

And they are both false...

Since If <EXP> Then is looking for something true, it will work (because 0 and "" are false...)

If we use == then it is case sensitive where it will look for whether they are both the same.

This is very complicated for me to explain :)

P.S- I may be wrong, and if I am, can one of you more knowledgeable peeps tell me :lmao:

Cheers,

Brett

Edited by BrettF

Share this post


Link to post
Share on other sites
ivan

You are correct in the documentation. You are comparing to a string, so perhaps you should cast your parameters as strings.

Test(1, 3, 0, 5)

;-------------------------------------------------
Func Test($a = "", $b = "", $c = "", $d = "", $e = "", $f = "")
    Local $Parms[7] = [0, String($a), String($b), String($c), String($d), String($e), String($f)]

    For $i = 1 To 6
        If $Parms[$i] = "" Then ExitLoop
        $Parms[0] += 1
    Next
    MsgBox(1, "", "Parms = " & $Parms[0])

    $Parms[0] = 0
    For $i = 1 To 6
        If $Parms[$i] == "" Then ExitLoop
        $Parms[0] += 1
    Next
    MsgBox(1, "", "Parms = " & $Parms[0])
EndFunc  ;==>Test

Share this post


Link to post
Share on other sites
Spiff59

I understand exactly what is taking place, and understand the reasoning behind it.

Minus seperate string and numeric data types, the behavior of the "=" operator in boolean compares is required.

It is also valuable, when necessary, to be able to determine between an ASCII "0" and a null-string.

My point is that, being useful, this behavior of the "==" operator ought to be mentioned in the documentation.

EDIT: Technically, I guess I should be trying to fight my way through the 'ticket' system and request someone update the docs, rather than posting here.

Edited by Spiff59

Share this post


Link to post
Share on other sites
BrettF
Spiff59

I posted what seemed to me a viable solution to the problem, though it's good to have a ref.

IVAN

Actually, I didn't have a problem, I prefer to pass a variable number of parameters in numeric format to the function. The loop using "==" works perfectly for me. I was just surprised that I had happened upon a currently undocumented difference between the two operators (= and ==).

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  

×