How To Use Arrays - Mitsubishi QD51 Programming Manual

Logic controller
Hide thumbs Also See for QD51:
Table of Contents

Advertisement

3 LET'S CREATE AND EXECUTE A PROGRAM

3.8 How to Use Arrays

3 - 29
Let's assume that a quantity of 100 data must be assigned to variables. Using A1, A2
... as variables, for example.
We need 100 lines
of code.
10 A1=52
20 A2=60
30 A3=17
100 variables will be required, and that's a lot of trouble. It is much more convenient to
use arrays in such instances.
It is necessary to tell BASIC that arrays will now be used. This is done by using the
DIM instruction.
DIM A(99)
This allocates locations to place data as shown below.
DIM A(99)
This allocates locations to place data as shown below.
A(0)
A(1)
A(2)
If 70 is to be assigned to A(50), enter the following.
A(50)=70
Now, the value within the parentheses can be specified by a variable, instead of a
number.
S=50 : A(S)=70
Since the value of S is 50, 70 will be assigned to A(50).
Now, let's consider assigning 100 data to variables again. When READ, DATA, and
FOR-NEXT from Section 3.5 and 3.6 are used.
10 DIM
A(99)
20 FOR
I=0 TO 99
30 READ A(I)
40 NEXT
50 DATA 52, 60, 70, • • •
How about this? The program is now amazingly short. Array variables become a useful
tool when repeating similar processes by specifying a variable for a value within
parentheses.
..................
A(3)
A(98)
MELSEC-Q
Since the number within the
parentheses is 99,
array entries 0 through 99
are allocated.
A(99)
3 - 29

Advertisement

Table of Contents
loading

This manual is also suitable for:

Ad51h-s3Qd51-r24A1sd51s

Table of Contents