Skip to content

CBOOL


Converts numeric or string expression to a boolean (Boolean)

Syntax

vb
declare function Cbool ( byval expression as datatype ) as boolean

Type typename

declare operator cast ( ) as boolean

End Type

Usage

vb
result = Cbool( numeric expression )
result = Cbool( string expression )
result = Cbool( user defined type )

Parameters

expression

a numeric, string, or user defined type to cast to a Boolean value

datatype

any numeric, string, or user defined type

typename

a user defined type

Return Value

A Boolean value.

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.

Examples

start GeSHi

vb
' 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

end GeSHi

Version

  • Since fbc 1.04.0

Dialect Differences

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

Differences from QB

  • New to FreeBASIC

See also

  • Cbyte
  • Cubyte
  • Cshort
  • Cushort
  • Cint
  • Cuint
  • Clng
  • Culng
  • Clngint
  • Culngint
  • Csng
  • Cdbl
  • Str

Back to DocToc

Translated from FreeBASIC official docs. Contact us for removal if infringed.
FreeBASIC is an open-source project, not affiliated with Microsoft