CBit converts anything to an integer that is suitable for use with MS SQL Server bit fields.
CBit ensures that a 1 or 0 will always be returned by the function, regardless of the data type or value of the input expression.
CBit returns a 0 or 1 value based on the following criteria (see table).
Criteria is applied in the order stated below. Once any criteria is recognized by CBit, no other criteria will be checked to determine the value of the bit field.
In other words, CBit goes with the first criteria that matches and then stops testing the variant input and returns the results of the first applicable test.
Variant Argument | CBit Returns |
------------------------------------------------------------------ | if variant can be converted to sub-type string and is considered alpha-numeric and if the value is: 'on', 'true', 'y', or 't' | 1 | if variant can be converted to sub-type string and is considered alpha-numeric and if the value is: 'off', 'false', 'n', 'f', or '' | 0 | if variant can be converted to a long value and is greater than 0 | 1 | if variant can be converted to a long value and is less than 0 | 0 | if variant is numeric but raises an error when being converted to long | 0 | if variant is null, empty or an array | 0 | if variant is an object and is set to anything other than Nothing | 1 | if variant is an object and is set to Nothing | 0 | if data type or value of passed variant argument is not given a value based on the above criteria | 0 | If CBit cannot determine the bit status of a particular variant entry, CBit always returns 0. | |