A question on ARRAYS. I have never successfully used them and I would like some help. I think I need an array to store some data that I need to pre-calculate. I can create it (ARRAY [1..32, 1..10] OF Position; ) but how do I populate the individual cells of the array? Do I need a pointer? Does anyone know the syntax? Similarly, if I want to access the data to pump it out to a variable it's all very confusing.
Thanks for any help, Matt.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You can initialise all the cells of the array, when you create it, for example :
Tablo : ARRAY[1..32,1..10] OF INT:=1,2,3,4,5,6,..
As this will fill the columns one by one, it to say that 1 will be placed in the first row of the first column, 2 in the second row of the first column, and so on.
You can have access to a cell indicating the column number and line number, for example if you want to have acces to the 4th row of the 3rd column, you have to indicate Tablo[3, 4].
With this you can read or write a cell.
You can use 2 variables to acces a cell, like this :
VAR
Num_row:INT;
Num_Column:INT;
END_VAR
Program:
Num_row:=4;
Num_Column:=3;
Tablo[Num_Column, Num_row]:=10; (The cell of the 4th row of the 3rd column is filled with the value 10)
Hope this helps you.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello There,
A question on ARRAYS. I have never successfully used them and I would like some help. I think I need an array to store some data that I need to pre-calculate. I can create it (ARRAY [1..32, 1..10] OF Position; ) but how do I populate the individual cells of the array? Do I need a pointer? Does anyone know the syntax? Similarly, if I want to access the data to pump it out to a variable it's all very confusing.
Thanks for any help, Matt.
Hello
For example you can create :
Tablo : ARRAY[1..32,1..10] OF INT;
You create an ARRAY with 33 columns and 11 rows.
You can initialise all the cells of the array, when you create it, for example :
Tablo : ARRAY[1..32,1..10] OF INT:=1,2,3,4,5,6,..
As this will fill the columns one by one, it to say that 1 will be placed in the first row of the first column, 2 in the second row of the first column, and so on.
You can have access to a cell indicating the column number and line number, for example if you want to have acces to the 4th row of the 3rd column, you have to indicate Tablo[3, 4].
With this you can read or write a cell.
You can use 2 variables to acces a cell, like this :
VAR
Num_row:INT;
Num_Column:INT;
END_VAR
Program:
Num_row:=4;
Num_Column:=3;
Tablo[Num_Column, Num_row]:=10; (The cell of the 4th row of the 3rd column is filled with the value 10)
Hope this helps you.
Thanks JAPIB, exactly what I was looking for my array is working well now. Merci bien et salut, Matt.