Skip to content

CBYTE


Converts numeric or string expression to Byte.

Syntax

vb
declare function Cbyte ( byval expression as datatype ) as byte

Type typename

declare operator cast ( ) as byte

End Type

Usage

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

Parameters

expression

A numeric, string, or pointer expression to cast to a Byte value.

datatype

Any numeric, string, or pointer data type.

typename

A user defined type.

Return Value

A Byte value.

Description

The Cbyte function rounds off the decimal part and returns a 8-bit Byte value. The function does not check for an overflow, and results are undefined for values which are less than -128 or larger than 127.

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

If the argument is a string expression, it is converted to numeric by using Valint.

Examples

start GeSHi

vb
' Using the CBYTE function to convert a numeric value

'Create an BYTE variable
Dim numeric_value As Byte

'Convert a numeric value
numeric_value = CByte(-66.30)

'Print the result, should return -66
Print numeric_value
Sleep

end GeSHi

Dialect Differences

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

Differences from QB

  • New to FreeBASIC

See also

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

Back to DocToc

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