CByte - VBScript


Overview

The CByte command in VB Script converts a numeric expression to a Byte value. It is commonly used to work with small integer values representing characters or low-level data in various programming scenarios.

Syntax

CByte(Expression)
  • Expression: The numeric value or expression to be converted to a Byte.

Options/Flags

None.

Examples

Convert an integer to a Byte:

Dim byteValue = CByte(123)

Extract the character code from a string:

Dim charCode = CByte(Mid$("Hello", 1, 1)) ' Returns 72 (ASCII code for 'H')

Common Issues

  • Overflow: If the input value is outside the range of Byte (-128 to 127), an overflow error will occur.
  • Invalid input: The input expression must be a valid numeric value. Passing non-numeric characters or empty strings can lead to errors.

Integration

CByte can be used in conjunction with other VB Script commands and tools:

  • VB Script String Functions: Use CByte to convert character codes to Bytes before performing string operations or comparisons.
  • File Input/Output: Use CByte to read or write small integer values from binary files.
  • Data Manipulation: Use CByte to convert data types for comparisons, calculations, or storage in different formats.
  • CLng: Converts to a Long integer
  • CShort: Converts to a Short integer
  • CDbl: Converts to a Double-precision floating-point number