This question originates from here. I tried this statement in VS to see what happens:
Len(Name <= 3)
According to this answer and also this one, Boolean should consume 4 bytes. According to MSDN, Len Function in VB
Returns an integer containing either the number of characters in a
string or the nominal number of bytes required to store a variable.
Name <= 3 should convert 3 to String and perform string comparison, returning a boolean value, so Len should evaluate number of bytes in it, which should be 4. For some reason, above code returns 2, regardless of the second parameter. In other words, Len(True) also returns 2. Tried for different platform targets (32 and 64) – same thing.
Why does Len(Boolean) return 2 instead of 4?
Len() is a legacy function, it should only be used in code that was ported from previous generation Visual Basic projects. Where it would typically appear in code that involved binary serialization of VB values. Sizes of basic types were different in those old versions.
Integerwas 16 bits for example, explaining the great number of bad pinvoke declarations you find in the web that use Long. AndBooleanwas a VARIANT_BOOL under the hood, a 16-bit value. Furthermore quirky by having itsTruevalue convert to -1 instead 1.Clearly adopting the .NET sizes would have been a heavily breaking change to a lot of data that exists in files written by a VB6 program. Or binary data sent across a TCP connection. Etcetera. Accordingly, the Len() function returns the legacy sizes.