Dim i As Integer = CType(False, Int32) // i is now 0
Dim j As Integer = CType(True, Int32) // j is now 1
The documentation on CType() doesn’t talk about this, but it also doesn’t explicitly forbidden it (like for Boolean -> String and String -> Boolean).
I don’t think it is a problem but you do need to be careful not to take the analogy too far. While it is true that FALSE is equivalent to the value zero, it isn’t always true that TRUE is the equivalent of the value one. Technically while FALSE is zero, TRUE is NOT ZERO.
Well, and sometimes you run into the problems.
In C people often write stuff like: if (value & 8). This means that the actual boolean value processed it 0 or 8. And if you assign that to a boolean property, it’s valid of course. Just later if you check for = 1,it will fail.
Right, Dale and Christian, that’s why I always cringe when I see “if mybool = true then”. It may be safe in Xojo because Booleans really can’t have any other values than false and true, but I see the same in C code, where this is just unsafe and wrong. shudder