Examples: CByte function
Example 1
' Convert string to byte
' Display value and data type
Dim nvar As Variant
Dim nstr As String
nstr = Inputbox("Number", "Enter any number", "0")
If Isnumeric(nstr) Then
nvar = Cbyte(nstr)
Messagebox nvar,, Typename(nvar)
Else
Messagebox nstr,, "Not a number"
End Sub
Example 2
'Convert an expression to a Byte
Dim MyDouble, MyByte
MyDouble = 125.5678 'MyDouble is a Double
MyByte = CByte(MyDouble) 'MyByte contains 126