Name
CBool Function
Syntax
CBool(expression
)-
expression Use: Required
Data Subtype: String or Numeric
Any numeric expression or a string representation of a numeric value.
Return Value
expression converted to a variant with a
subtype of Boolean (True or
False).
Description
Casts expression as a Variant with a
Boolean subtype. Expressions that evaluate to
are converted to False (0), and expressions that
evaluate to nonzero values are converted to True
(-1).
Rules at a Glance
If the expression to be converted is a string, the string must act as
a number. Therefore, CBool("ONE") results in a
type mismatch error, yet CBool("1") converts to
True.
Programming Tips & Gotchas
You can check the validity of the expression prior to using the
CBoolfunction by using theIsNumericfunction.When you convert an expression to a Boolean, an expression that evaluates to is converted to
False(0), and any nonzero number is converted toTrue(-1). Therefore, a BooleanFalsecan be converted back to its original value (i.e., 0), but the original value of theTrueexpression can’t be restored unless it was originally -1.
See Also
| IsNumeric Function |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access