Sign in to follow this  
Followers 0
IO_Rack

Initializing a String Array

3 posts in this topic

I got some good information from this post on string arrays. TW Controls says: Therefore if I wish to initialize a string array to 'Null', then I should create new String tags (for example) as follows: NullStrings[0] ' ' NullStrings[1] ' ' NullStrings[2] ' ' NullStrings[3] ' ' NullStrings[4] ' ' NullStrings[5] ' ' Each above item being of zero length. then... COP Source: NullStrings[0] Destination: MyDataStrings[0] Length: 6 This should copy the zero length strings (Element for Element) to MyDataStrings[0] through MyDataStrings[5]. A) Do I understand this correctly? B) Is this the preferred method for initializing a string array? It seems a bit wasteful as I am initializing a 100 element array in the application I am working on. I tried making the source 'NullStrings' without the '[0]' and ended up with the 'unexpected' results they referred to in the above linked post. I also tried the FLL instruction but it wouldn't compile. I looked at the String Delete (DELETE) instruction but I did not see how this could be done without creating a loop and indexing the array. I struggled with this a bit on Friday. This is easy enough to test but I don't have the means this weekend. I would like to show up Monday prepared to finish this job. Thanks.

Share this post


Link to post
Share on other sites
I can't test this, and haven't tried it before, but would it work to use the FLL instruction to move a zero value into your string array?

Share this post


Link to post
Share on other sites
I tried that. It wouldn't verify. I don't remember the exact error but it was something to the effect of 'wrong data type'. The help on the FLL instruction does not specify String as a valid data type but then neither does the COP instruction. I guess it's because COP copies bit for bit so it doesn't matter what data type it is. At least that is my understanding. Thanks for the suggestion. EDIT: I overlooked that you used a '0' instead of a string. I would imagine that still wouldn't verify because they are incompatible data types. But then again, many of the Rockwell instructions do automatic conversions. I'll have to play around with that one. EDIT AGAIN: OK, I'm being stupid here. I can compile without being online. Your example does compile. I don't know how it will react but it looks promising. If it does the conversion it should fill ASCII 0 (Null) into the array. Or would that be if it doesn't do the conversion? Edited by IO_Rack

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0