O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

CBool Function

Named Arguments

No

Syntax

CBool(expression)
expression (required; String or Numeric)

Any numeric expression or a string representation of a numeric value

Return Value

expression converted to Boolean data type (True or False)

Description

Casts expression as a Boolean data type

Rules at a Glance

When a numeric value is converted to Boolean, any nonzero value is converted to True, and zero is converted to False.

If the expression to be converted is a string, the string must be capable of being evaluated as a number, or it must be "True" or "False". Any other string generates a runtime error. For example, CBool("one") results in a type mismatch error, whereas CBool("1") is converted to True, and CBool("True") is converted to True.

Programming Tips and Gotchas

  • You can check the validity of the expression prior to using the CBool function by using the IsNumeric function.

  • Like most of the conversion functions, CBool is not actually a function in the Microsoft.VisualBasic namespace. Instead, it is similar to a Visual C++ macro; the compiler translates the function call into inline code.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required