183
14.3.1.2 Variables
Variables are names that represent information. The information can change as the variable is modified by statements.
Naming rules for Variables:
1. All variable names must start with an alphabet
character. Other characters in the variable can
be characters or numbers.
2. Punctuation, the “_” character, spaces and non-
alphanumeric characters cannot be used in
variable names.
3. Variable names longer than 32 characters are
not allowed.
4. Reserved words cannot be used as Variable
names.
Examples of good variable names:
Temperature LimitSwitch41
PresetCounter
x
win
errorcode
Examples of bad variable names:
Error
3wayswitch
Run_Lamp
mod
OverCurrentSensingRelayTrippingPoint
begins with a number
illegal character “_”
reserved word
longer than 32 characters
There are 5 different variable types:
Type
Description
Range
bool
1 bit (discrete) variable
0,1
char
8 bit (byte) variable
±128
short
16 bit (word) variable
±32767
int
32 bit (double word) variable
±4294836225
float
32 bit (floating point) variable
±4294836225
Declaring Variables
Variables must be declared before being used. All variable declarations must be made before any other statements in the
macro. To declare a variable, specify the type then the variable name.
Example of a simple declaration
int
n
If there more than a single variable of a particular type is needed, they can be declared in the same statement by separating
them with commas.
Example of multiple variable declaration
short
a, InputBlock1, color
Declaring Arrays
Macros support one-dimensional arrays. To declare an array of variables, specify the type, the variable name then the
number of variables in the array enclosed in brackets “[ ]”. Arrays are 1 to 4096 variables in length. (Macros only support up
to 4096 variables per macro)
Example of Array declaration
int
g[10]
Variable and Array Initialization
There are two ways variables can be initialized:
1.
By statement using the assignment operator (=).
Example of statement initialization
int n,
V[4]
n = 399
V[0] = 24
2.
During declaration
Example of initialization during declaration
char i='z', a, b=3
The declaration of arrays is a special case. An entire array can be initialized during declaration by enclosing comma
separated values inside curly brackets “{ }”
Example of Array initialization at declaration
int V[4]={24, 15, 5, 0}
Summary of Contents for MMI-1500
Page 2: ...ii...