Working with Bytes
A byte variable can contain a single byte of data-that is, a number from 0 to 255. Doesn't sound very useful, does it? Bytes aren't often used alone, though; they're often used in arrays, where a single byte array can represent a stream of binary data. For example, files on a computer's hard drive are a simple one-dimensional array of bytes. A file that's 1KB in length has 1,024 elements in its array, and can be contained with a byte array in an administrative script.
Bytes in VBScript
Your most frequent use for byte variables will be to pass data to WMI functions that require a byte array. You'll usually work with bytes in the form of an array, where the data inside the array represents a file or some other binary data. Still, bytes are reasonably rare in administrative scripts, which is why I won't bore you with a long example. You'll see one or two examples elsewhere in this book that use bytes; I'll call your attention to them and explain them in a bit more detail at that time.
Converting Byte Data
The CByte() function converts data to a byte. Generally, only numeric data in the range of 0 to 255 can be successfully converted to a byte.
Dim iDouble, bByte
iDouble = 104.76
bByte = CByte(iDouble)
In this example, bByte now contains the value 105, which is the closest whole number to what iDouble contains.
|