Byte

Description

Converts a number into a Byte datatype or obtains a Byte value stored in a blob.

Syntax

Byte ( stringorblob )

Argument

Description

stringorblob

A String or any numeric datatype that you want to return as a Byte, or a Blob datatype in which the initial value is the Byte value that you want to return. The stringorblob variable can also have an Any datatype as long as it references a string, integer, uint, long, longlong, or blob.

Returns

Byte. Returns the value of the stringorblob variable as a Byte datatype if it succeeds; it returns 0 if the stringorblob variable is not a valid PowerScript number or if it has an incompatible datatype. If stringorblob is null, Byte returns null.

Usage

If the number you convert exceeds the upper range of the Byte datatype (>255), the Byte method returns the difference between the number you pass in the stringorblob argument and the nearest multiple of 256 below that number.

If you pass a blob in the stringorblob argument, only the value of the initial character is converted to a byte value. (There is no “overflow” when you use a blob argument.) To get the byte value for a character at a different position in the blob, you can use the GetByte method.

Examples

Example 1

This example converts a string entered in a SingleLineEdit control to a byte value:

Byte ly_byte

ly_byte = Byte(sle_1.text)

If the text entered in the SingleLineEdit is 4, the byte value of ly_byte is 4. If the text entered is 257, the value of ly_byte is 1. For 256 or text such as “ABC12”, the value of ly_byte is 0.

Example 2

This example returns the ASCII value of the initial character that you enter in a SingleLineEdit control:

Byte lb_byte

Blob myBlob

myBlob = Blob(sle_1.text)

lb_byte = Byte(myBlob)

See also