Byte Variable Declaration (Syntax 1)

In VAR blocks, syntax 1 of BYTE is used to declare global, symbolic variables that are either byte-sized, or are any array of bytes.

For example:

VAR
  byte Temp                      'Temp is a byte
  byte Str[25]                   'Str is a byte array 

The above example declares two variables (symbols), Temp and Str. Temp is simply a single, byte-sized variable. The line under the Temp declaration uses the optional Count field to create an array of 25 byte-sized variable elements called Str. Both Temp and Str can be accessed from any PUB or PRI method within the same object that this VAR block was declared; they are global to the object. An example of this is below.

PUB SomeMethod
  Temp := 250                    'Set Temp to 250
  Str[0] := "A"                  'Set first element of Str to "A"
  Str[1] := "B"                  'Set second element of Str to "B"
  Str[24] := "C"                 'Set last element of Str to "C" 

For more information about using BYTE in this way, refer to the VAR section's Variable Declarations (Syntax 1) and keep in mind that BYTE is used for the Size field in that description.

Unless otherwise noted, content on this site is licensed under the
Creative Commons Attribution-ShareAlike 4.0 International License.