Returns the expression converted to a byte data type (Byte).

expressionThe expression to evaluate and convert to a byte.

* The Byte data type is a Value data type.
* The "expression" can be any numerical value between 0 to 255 (Integer).
* A byte takes up a single byte of computer memory and can have a value from 0 to 255.
* This data type is commonly used for file formats and data conversions.
* If the expression is not a floating point number then it is rounded to the nearest integer.
* An overflow error will occur if the value is out of range.
* Any fractional parts greater than 0.5 are rounded up.
* Any fractional parts less than 0.5 are rounded down.
* Any fractional parts equal to 0.5 are rounded to the nearest even number.
* This type of rounding is called banker's rounding and its purpose is to compensate for a bias that could accumulate when adding a lot of 0.5 fractions.
* For a full list of conversion functions refer to the Explicit Conversion page.
* For the Microsoft documentation refer to learn.microsoft.com

Debug.Print CByte(10)           '= 10  
Debug.Print CByte("some text") '= "Type mismatch error"
Debug.Print CByte(256) '= "Overflow error"
Debug.Print CByte(-1) '= "Overflow error"

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top