Function Coerce Make Class

CoerceToBoolean

"Coerce String To Boolean" Return the Boolean value whose in-memory representation is the same as the first two characters in string vString.

Signature (Visual Basic / VBA)

Public Function CoerceToBoolean( _
    ByVal vString As Variant _
    ) As Variant

Code Example

    CoerceToBoolean(Chr$(0) + Chr$(0)) = False
    CoerceToBoolean(Chr$(255) + Chr$(255)) = True
    IsNull(CoerceToBoolean(Null)) = True

Parameters

Parameter Description
vString The string whose first two characters are to be interpreted as a Boolean value. Function returns Null if vString is Null or cannot be fixed up to a String.

Notes & Version History

Note Function generates the Visual Basic Error "Illegal Function Call" if vString is less than 2 characters long (the size of a Boolean value).
Note If vString is more than two characters long, the leftmost two characters are coerced to a Boolean value.
Note This function first converts the string from Unicode to the default code page of the system.
v1.3 Change Removed 16-bit support from this function.