Use elements of a string array

LITStudent

Member
Join Date
Jan 2016
Location
Ireland
Posts
5
Hello,

RSLogix5000

I need to take a word from a list of 10 stored in a string array size 10, and copy or move it into a another string which is not an array. I have tried mov and cop but the different data types is an issue anybody have a smart solution,

thanks for any help you can give.

Student For Life.
 
So based on the example above by nhasten I can see how you move an element of your 'strings array' to the 'another string' so you end up with 'long text here' copied to the 'another string' array. That's OK, but my version of the 'strings array' has 10 different words which a user can scroll through on a HMI when they select a word I need to copy that array element (word) to the 'another array'.
 
Please show the two arrays. As far as we know you have two arrays of strings and you wish to copy from one to the other. If that is not what you are trying to do then we need more information.
 
So based on the example above by nhasten I can see how you move an element of your 'strings array' to the 'another string' so you end up with 'long text here' copied to the 'another string' array. That's OK, but my version of the 'strings array' has 10 different words...
StringsArray is an array of 10 different strings (datatype is STRING[10]). You can see that:


  • First element in the array is StringsArray[0] = 'Element 1'
  • Second element in the array is StringsArray[1] = 'Element 2'
  • Third element in the array is StringsArray[2] = 'A long text here'
  • StringsArray[3] to StringsArray[9] are empty strings

AnotherString and OneString are simple strings (datatype STRING). Remember: a string in Logix controllers is in fact a duple of two elements, an array of SINT (DATA) and a DINT (LEN).

Said that, in the first rung I'm copying the third element of StringsArray into AnotherString. The Lenght parameter in COP instruction is 1 because I want to copy one element (not one character) of the array.

... my version of the 'strings array' has 10 different words which a user can scroll through on a HMI when they select a word I need to copy that array element (word) to the 'another array'.
I suppose you use a List or other visual object to select the word, write an index to a tag, and use that tag to point the element in your array. That's ok. However, I'm a bit confused about the destination. In your first post you said:

I need to take a word from a list of 10 stored in a string array size 10, and copy or move it into a another string which is not an array.
Is the destination a simple string or an array of strings?
 
So I can see how talking about two different arrays was confusing probably chasing my own tail now!

I have attached the controller tags what I need to do is move any of the selected words from the array of strings: HMI_Words_Select_Array into the simple string: HMI_Word.

Thanks for taking the time to look this over.

TAGS.jpg
 
In the attached image:

  • Pointer is a DINT variable, from 0 to 9.
  • Each time ControlBit is True, the COP instruction will copy the pointed element to HMI_word.
Your HMI application has to write the Pointer value each time you select an item of the list. In other words, each item of the list shown on the HMI has an associated value (0=PLC, 1=DESIGN...), and that value is written to Pointer when you make the selection.

Notes:

  • You must ensure that Pointer is never lower than zero or greater than 9. The controller will fail if you use an out-of-range index in your array.
  • It's up to you how to clear ControlBit. Also you can try removing ControlBit.

COP.PNG
 

Similar Topics

Per title, I have an example string array Foo of datatype STRING[10] and index Bar of type DINT EQU('False',Foo[Bar]) works functionally but on...
Replies
8
Views
2,939
Hello there! I've used the information on this site before, but this is my first time posting. I'm using CCW for the first time, and was...
Replies
5
Views
716
Can someone explain the jumper between the elements? Does it do anything? See attached jpeg.
Replies
4
Views
684
Can you please tell me if it is possible to add comments to array elements in Codesys 3.5? For example, Control Expert (Schneider Electric)
Replies
4
Views
1,504
Hi Guys, Does anyone know a good way to count populated elements in an array? I have 2 arrays of 60 elements which hold strings. When a string...
Replies
29
Views
6,053
Back
Top Bottom