TIA portal - choosing array number based on INT

rQx

Lifetime Supporting Member
Join Date
Oct 2010
Location
Trelleborg
Posts
1,051
Hi!

I'm working on a program with several arrays. I have one integer that I want to use to choose witch array will get assigned a value. For example:

I have a Dint value of 1234

I have a Int (my choosing tag) with the value of 5

I have a Array[1..10] of Dint

Now I want to move the Dint value to the Array number 5. Is there a easy way of doing this so that I don't have to use one comparator for each situation? I have several of these arrays and I don't want to make any unnecessary (no idea how to spell that) work.

/Tim
 
You didn't say where in the array '5' you want to move the DINT to..
But I that is a mute point for now, sounds like you need a 2-dimensional array.
 
I want to use a move instructions to move the value of my Dint. To the fifth array (array[5]) without using alot of compare and stuff.
 
Hi,
Just to clearify what you want to achieve,
do you mean that you have only one array with 10 elements or do we speak of multiple array's?

Are you working in STL or SCL?

If it's STL, the easiest way would be to use indirect adressing.


Assuming STL, one array and that your array is declared locally it could look something like this:


L P##"name of your array variable"
LAR1
L "INT pointing to element"
SLD 5
+AR1
L "DINT with value to store in array"
T D[AR1, P#0.0]



/ W



EDIT: Oooops! missed that you are working in TIA. Above mentioned regards Step 7 Classic
 
Last edited:
I'm using ladder and I have

>Array Array[1..10] of Dint

This is a Array that consist of 10 Dint values.

I have an Integer witch we can name: "Choose Int"
I have an DInteger with a value I want to assign to diffrent positions in my array.

If my "Choose Int" is set to 5, I want to move the Dinteger to the fifth element in my array.

>Array Array[1..10] of Dint
array[1]
array[2]
array[3]
array[4]
array[5] <----- this element

I know I can use a compare instruction for each element of the array to move the Dinteger to the correct position. What I wan't to know is if there is any other, better (smaller) way to do it. Since this is a scenario that will occur often in my program.
 
Code:
L    L#5 ; //or     L    #ChooseInt ;
T    [B][COLOR="blue"]#arr[/COLOR][/B][5] ;


?

You should not use the name "array[x]" ( it is used from system )


arr is the array !
arr[5] is the element 5 of the array arr
 
Last edited:
You don't mention which CPU family you are using.
Is it a S7-1200 or a S7-300/400.
This makes a difference as the 1200 does not have STL capability.
 
Code:
L    L#5 ; //or     L    #ChooseInt ;
T    [B][COLOR="blue"]#arr[/COLOR][/B][5] ;


?

You should not use the name "array[x]" ( it is used from system )


arr is the array !
arr[5] is the element 5 of the array arr

He likely did in this case so that it was obvious to those in the forum that it is an array. If I am positing an example of an array I usally name it "SomeArray" or similar to make that point clear.
 
s7-1200 is the CPU.

Thanks for all the effort into helping me.

I just stumbled upon the block "field_write" this is exactly what I need.

You have a "somearray[1]" output
A index tag witch will choose witch component of the "somearray[1]" input to write to
And you have a Value input with the vale to write. This is exactly what I needed!

Thanks for all the help, I'll be sure to tell the CPU next time I post a thread. I've never used other CPU then s7-1200 with TIA portal so TIA portal is s7-1200 for me :)
 
I'm using ladder and I have

>Array Array[1..10] of Dint

This is a Array that consist of 10 Dint values.

I have an Integer witch we can name: "Choose Int"
I have an DInteger with a value I want to assign to diffrent positions in my array.

If my "Choose Int" is set to 5, I want to move the Dinteger to the fifth element in my array.

>Array Array[1..10] of Dint
array[1]
array[2]
array[3]
array[4]
array[5] <----- this element

I know I can use a compare instruction for each element of the array to move the Dinteger to the correct position. What I wan't to know is if there is any other, better (smaller) way to do it. Since this is a scenario that will occur often in my program.

Indirect addressing is possible,in this case
Move Dinteger to Array["choose_Int"]
 

Similar Topics

Hi PLC people, think about this scenario: The PLC is somehow connected to the same network with the facilities` network. Then someone connects to...
Replies
2
Views
79
Hello, good morning, I have been having two problems with the Tia Portal software. The first is that I have installed it on my computer and...
Replies
5
Views
181
Hello all! So I have one project with a S7-1214 and a MTP1500 "Project1" and one project with another S7-1214 "Project2". Both of these PLC:s need...
Replies
6
Views
110
Hello, i am using profibus as communication between plc and fanuc arm. I can easily send inputs from plc to arm, but i can't monitor any outputs...
Replies
0
Views
46
Hello, I need to write the following program in Ladder language, but I could not integrate the Fibonacci sequence into the ladder. Can you help...
Replies
22
Views
472
Back
Top Bottom