Skip to content
Paul Squires edited this page Oct 19, 2026 · 3 revisions

Home › Converting Data Types › CBool

CBool

Converts a number, or the text "true" or "false", to a boolean; zero gives false.

Syntax

Declare Function CBool ( ByVal expression As datatype ) As Boolean
Type typename
Declare Operator Cast ( ) As Boolean
End Type

Parameters

  • expression
  • datatype
  • typename

Description

The CBool function converts a zero value to False and a non-zero value to True.

The name can be explained as 'Convert to Boolean'.

If the argument is a string expression, it is converted to boolean using a case insensitive to the string "false" to return a False value or "true" to return a True value.

Return Value

A Boolean value.

Remarks

Usage

result = CBool( numeric expression )

result = CBool( string expression )

result = CBool( user defined type )

Dialect Differences

  • Not available in the -lang qb dialect unless referenced with the alias __Cbool.

Differences from QB

  • New to FreeBASIC

See also

Examples

' Using the CBOOL function to convert a numeric value

'Create an BOOLEAN variable

Dim b As Boolean

'Convert a numeric value

b = CBool(1)

'Print the result, should return True

Print b

Sleep

Category: Converting Data Types
Kind: function


Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.

Clone this wiki locally