Step 7 help with Strings and UDTs

uptown47

Lifetime Supporting Member
Join Date
Feb 2008
Location
Over there, next to those boxes
Posts
1,146
I've done a search on this forums (and Siemens forums) trying to get my head around UDT's and strings.

I found an example by Daniel Chartier from a long while ago detailing a way of explaining UDT's by imagining a record collection:

Code:
ALBUM_1: ALBUM{

[COLOR=black]Record number (INT): 1[/COLOR]

[COLOR=black]Title (String[30]): White Album[/COLOR]

[COLOR=black]Artist {STRING[20]): The Beatles[/COLOR]
[COLOR=black]Genre (STRING[15]): Classic Rock[/COLOR]
[COLOR=black]Date of publication (DATE): July 1968[/COLOR]

[COLOR=black]...[/COLOR]

[COLOR=black]}[/COLOR]

I started to create this as an example to help myself understand UDTs and also strings but I can't find any way of 'MOVE'ing a value into a string.

The accumulators etc only hold 4 characters but even....

Code:
L  'ABBA'
T  CDs.Artist   // This is a field in my UDT

... doesn't work.

I know that you can MOVE a string from one place to another with BLKMOVE but not sure how you initially put a value into it (or maybe you can't???)

I've read how other people prefer to use CHARs etc...

This isn't for a real program, just me trying to understand more about the darker depths of S7.

I've posted similar questions before and found some of my old questions as I searched. I found an example posted by LD utilising an ARRAY of UDTs etc but it was a bit above my head.

I basically would like to see how you could do a very very (very) simple example of a UDT utilising a couple of data types including a STRING. Just to see how it would be used in a very simple program.

Anyone got anything like that? Or any reading material they could link me to??

Berger only seems to give a brief overview and other forms of reference are either too complicated or only reference RS Logix.

Many thanks for any help

;-)
 
Manipulating STRINGs in STL is really cumbersome.
'ABBA' is 4 CHARs, not a STRING[4]. A STRING in addition to the chars uses the 1st byte to hold the reserved string length, and the 2nd byte to hold the actual used string length.
Copying STRINGs can be done with SFC20 BLKMOV. Concatenating and joining STRINGs can be done by using library functions.
But generating the contents of STRINGs dynamically in code in STL, LAD or FBS is code intensive and error prone.

In SCL you could write
"CDs".artist := 'ABBA' ;

edit: damn, forgot a ":" in the above SCL code snippet.
 
Last edited:
Hi Jesper,

Thank you for the info. I've never done any SCL. I'm not sure my software can do it (I'm just using basic Step 7).

I did read something about the first 2 bytes of the string but even:

L 'a'
T CDs.Artist

doesn't work....

Artist is showing as String[4] in the variable declaration table.
 
Last edited:
Code:
L  'ABBA'
T  CDs.Artist   // This is a [B]field in my UDT[/B]
... doesn't work.

This makes me ponder, if you did declare a data in datablock (or stat of FB) of type "yourUDT" ?

What I suggest you to do is, first learn to use UDT with basic, bool, int, dint etc. datatypes. Then learn ot use STRING datatype. And just after that lear how those are used together.
 
Last edited:
You cannot monitor STRINGs in a VAT in STEP7.
But you can monitor the individual bytes of the STRING.
Point the VAT to the individual bytes, displayed as decimals for the 1st and 2nd byte, and as Chars for all the subsequent bytes.
 
I'm not sure I understand what you mean. I haven't managed to monitor it because it won't let me write anything to it.

I've zipped the software up as a library in case you get a chance to look at it.

I'm off to the dentist in a mo and not back until Monday. Would love any suggestions on how to get this work or any clarification on what I'm missing.

Many thanks

;-)
 
L 'a'
T CDs.Artist
doesn't work....
Thats what I am trying to tell you.

In the above code, 'a' is a single CHAR, whereas CDs.Artist is a complete STRING[4]
The biggest datatype you can address with "T" (transfer) is a doubleword (4 bytes).
In STL, LAD or FBD, a STRING can only be manipulated by pointers.
So the code editor will refuse to accept T CDs.Artist
 
Just for completeness sake...
You CAN very tediously set individual characters of a STRING in STL, LAD and FBD.

Like:

L 'A'
T "CDs".artist[1]
L 'B'
T "CDs".artist[2]
L 'B'
T "CDs".artist[3]
L 'A'
T "CDs".artist[4]
 
As already stated, strings can only be accessed by area pointers. Here's some example processing that will load a hardcoded string into the artist field. It also shows a VAT table being used to monitor the results.

bert.jpg
 
Jesper, LD,

A big thanks for your posts. I've just read through them and downloaded the example that LD posted.

I'm going to go through that this morning and will post back with any questions.

Reading the posts though it seems straight forward enough and Jespers comment about passing a Char into a String makes perfect sense so I can see why that wasn't working.

Many thanks

;-))
 

Similar Topics

I really struggle with STL in Siemens Step 7 Classic. I'll learn chunks, but then I don't use it enough to retain and build on the knowledge. When...
Replies
17
Views
3,216
Hi, Can someone translate this for me please, or at least help to explain what the instructions mean? SET SAVE =...
Replies
17
Views
4,618
Hello everyone I am new to Siemens Step 7 and having some issues I was going to add the a FC to OB1 (Network 28 In Image 1) But it was asking...
Replies
9
Views
2,392
Hello everyone I'm new here and was hoping someone can help me out. I have a pneumatic punching/ bending machine that broke down running on a...
Replies
39
Views
5,172
If I go online via the PC Adapter, all the blocks are there and all is good. If I go online via the CP-443 via IE, all the blocks then disappear...
Replies
6
Views
1,475
Back
Top Bottom