Telling the difference between assignment and equals comparison

Started by chelmite, February 21, 2013, 08:52:07 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

chelmite

How does one assign the result of a Boolean expression to a Boolean variable in the following case:

Dim A, B As Boolean

A = B = False

I want to compare B with the False value and assign the result to A. Is that what I'd get? (In most other languages, this would be written A = B == False, where == is the comparison operator and = is the assignment operator.

Or would I be assigning False to B and then False to A?

Jumpy

A = not B
comes to mind...

Otherwise if it has to be complicated
A = (B=false)
works, too

and because the VBA Interpreter/Compiler is not that dump, you can even ommit the brackets, so
A = B=false
works, too. And you are where you started from...

chelmite

So, in
  a = b = false,
is the left "=" the assignment operator, and
is the right "=" the comparison operator or the assignment operator?

And, in
  a = (b = false)
I assume that the left '=' operator is assignment,
but I don't know whether the right '=' is assignment or the equality comparator.

Thanks

JuneTheSecond

I think you are right.
In "a = b = false", the first "=" is assignment operator, and the second "=" is comparison.

If b is false, the sentence "a = b = false" does not give the result "a = b" but "a = true", because "b = false" is true.

In Visual Basic, the "=" operator is used for both comparison and assignment.
Very much confusing.
Not limetted in Visio.
Best Regards,

Junichi Yoda
http://june.minibird.jp/