Strange behavior of multiple assignment in visual basic

Some bug got me investigate again.

txt1.Enabled = txt2.Enabled = radioButton.Checked

This language construct will not work in visual basic as it would in C++. If you unchecked the option you'll get txt2 enabled and txt1 disabled, because visual basic does not assign values like that. Does it evaluate first expression txt2.Enabled = radioButton.Checked as "true == false" (in C++) and thus assigning txt1.Enabled the value "false"? Hmm ... does language itself determine what is assignment and what is not?

So I experimented a bit:


Dim a1, a2, a3, a4, a5 As Boolean
a1 = False
a2 = False
a3 = False
a4 = False
a5 = True
a1 = a2 = a3 = a4 = a5

This will produce all values false except a5. That means that it is not evaluated like this either:


a1 = (a2 == (a3 == (a4 == a5)))

Just in case, I tried to resolve this again: a3 = a4 = a5. Surprise, no alternating values seen. Tried original problem again and I almost though that I saw wrong until I discovered this:


a1 = True
a2 = True
a3 = True
a4 = True
a5 = False
a1 = a2 = a3 = a4 = a5

The result is a1 is true, a5 is true, the rest is false? Different behaviour depending of the state it's in? This needs more thinking ... why isn't a1 true in first case? Why are there no alternating values in between? And finally, how does a3 for instance know what is behind it in expression since it would have been modified if it was the first variable, but is not when it is in the middle?

PS.: Here is this problem described by some other guy on this forum :

But the answer he got is probably not correct, since the alternating values version cannot be reproduced ( or at least I didn't know how ).


Next: How to get last inserted N rows with oracle SQL