array in step7

Tsørensen

Member
Join Date
May 2004
Posts
25
i have to create an array that lookes like this

foo[1] => 'text1'
foo[2] => 'text2'
foo[3] => 'text3'
foo[4] => 'text4'
foo[5] => 'text5'
foo[6] => 'text6'


i have made a datatype that looks like this

foo__________array[0..6]
____________string[5]

but how do i use it ?

i have tryed to define the array i a datablok like this

nr1_____udt1_____ 'text1'
nr2_____udt1_____ 'text2'



what is wrong ??, i tryed to follow the manuel but what have i done wrong ?
 
i have to create an array that lookes like this

foo[1] => 'text1'
foo[2] => 'text2'
foo[3] => 'text3'
foo[4] => 'text4'
foo[5] => 'text5'
foo[6] => 'text6'


i have made a datatype that looks like this

foo__________array[0..6]
____________string[5]
This is correct apart for the array[0..6] which should be array[1..6].

If you're defining an array, you cannot enter default values. To get the values into the array, you have the choice between various methods:
  1. Switch from Declaration View to Data View and enter every single values by hand
  2. Since every value is 'text' + a number you could write a routine to enter the values. The string function to use is CONCAT.
  3. You can also enter the individual values by declaring a variable table in Monitor/Modify values and enter every single value by hand. This is essentially the same method as the first.
    [/list=1]
    Kind regards,
 
thanks !

One last question how do i move a string

i tryed:


db20.bitter.produkter[1] --IN|move|OUT--db20.produkt

but is says:

Actual data type STRING [13] does net fit the formal type og the formal parameter ?
 
You can't copy/move strings directly like that.

Instead, there are a couple of ways to do it:

1) The second byte of the string contains the actual length of the string (refer to the Siemens Help). By refering to this value, you can create "Any Pointers" that will point to the source and destination of your string data, and will handle any length dynamically. (Use SFC20, "BLKMOV").

2) Again, using the string length byte, you could write your own loop code to copy the string bytes one by one. This would work faster than SFC20 (SFC 20 has a lot of overhead).

Another way is to scrap String types altogether and use characters instead. They are easier to handle and monitor. There are several threads here that talk about this already, so you may want to take a look at that.
 
I forgot to mention something....

Regarding your first question, if you want to initialize array elements, just enter the initial values as a comma seperated list in the initial value field. For instance, in your case you would enter 'text1','text2','text3','text4','text5','text6'.
 
Thanks S7Guy,

yet another piece of new info for me. Maybe I've heard about it before, but then I surely had forgotten about it. You see: we're never too old to learn!

Kind regards,
 
Well, it's a good thing we're never too old to learn, or else I would have stopped learning a long time ago. :)

Actually, even though you can enter the presets as I decribed, it is of little actual value in real life unless you had just a small array. I mean, what if you had 1000 items? That would get tedious. Instead, for large arrays I prefer to load the defaults in my start-up OBs and use a loop function.
 
thanks alot guys but suddenly i don’t know if it’s the best solution I chose for the problem.


The problem is this:

I have a byte that describe the product that is produced at the moment.

If the byte is = 00000001

Then I have to write “34 procent” in WinCC

And if the byte = 0000010

Then I have to write “40 procent oe” in WinCC

And so on.

For that job I have created a array[‘13’]

And had in mind to move the value from the array to a string variable

Eg.

if byte1.0 == 1 then move arrayname[1] => product
if byte1.1 == 1 then move arrayname[2] => product


but I can see that this is NOT a easy solution, anyone have a better suggestion how to make this ?

I have thought about C-script and getting the text from a file, but as you properly can see I am new to the whole siemens way of doing things.
 
Its better to describe what you want to achieve than how you think to solve it.

The problem could be that you have not completely figured out how to split the job between the PLC and WINCC.

Its not obvious why you want string arrays in the PLC.
To me it looks like recipe or batch handling. But I am not sure.
 

Similar Topics

Hello all.... I'm still coming to terms with Siemens PLC programming after many years of only knowing AB, so be gentle - :rolleyes: I've got an...
Replies
11
Views
4,338
Hi' I am trying to make a "lookup" in an table I have created in an array. My tabel looks like this: 0,920 21,75 200,1 0,00047 0,910 24,99...
Replies
3
Views
3,698
Hey Guys.. Here's my problem. I have an array of 9 characters, a "part number". I need to compare this array to another part number that is...
Replies
10
Views
6,605
Hello, I have created a FB and in the declaration, added an array of bools as a stat and cannot figure out how to add a comment to individual...
Replies
5
Views
3,388
I've got an application where a robot is running 10 objects one after another past a camera so I need to buffer the result of the camera test...
Replies
20
Views
9,323
Back
Top Bottom