3 - 29 3 - 29
MELSEC-Q
3 LET'S CREATE AND EXECUTE A PROGRAM
3.8 How to Use Arrays
Let's assume that a quantity of 100 data must be assigned to variables. Using A1, A2
... as variables, for example.
10 A1=52
20 A2=60
30 A3=17
………
We need 100 lines
of code.
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.
Since the number within the
parentheses is 99,
array entries 0 through 99
are allocated.
DIM A(99)
This allocates locations to place data as shown below.
A(0)
A(1)
A(2)
A(3)
A(98)
A(99)
………………
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.
Содержание A1SD51S
Страница 183: ...11 13 11 13 MELSEC Q 11 INSTRUCTIONS AND FUNCTIONS RUN Before swap A 0 H924 A 1 H1159 After swap A 0 H1159 A 1 H924 OK...
Страница 331: ...11 161 11 161 MELSEC Q 11 INSTRUCTIONS AND FUNCTIONS REMARK See the CON ON OFF STOP and ZOPEN functions and Section 7 4...
Страница 557: ...11 387 11 387 MELSEC Q 11 INSTRUCTIONS AND FUNCTIONS REMARK See the CHR SPACE and SPC functions...
Страница 629: ...11 459 11 459 MELSEC Q 11 INSTRUCTIONS AND FUNCTIONS REMARK See the ZOPEN ZSEND and ZCNTL instructions and Section 7 3 4...
Страница 645: ...11 475 11 475 MELSEC Q 11 INSTRUCTIONS AND FUNCTIONS REMARK See the ZEVENT ZSIGNAL and DEF ZEVENT instructions...