SCL operator question TIA Portal V15

dahnuguy

Member
Join Date
Mar 2007
Location
SC
Posts
720
I just found a piece of code using an operator "+="

IF tag1 AND tag2 THEN
tag3 += tag4;
tag5 := tag5 + tag6;
END_IF;

I don't find "+=" anywhere in operators list, is this a typo?
 
If I had to guess (and it is a complete guess) I'd suggest that it's adding tag3 to tag4 and storing the result in tag4. Would that make sense, given what you know of the process?
 
tag3 += tag4;
tag3 := tag3 + tag4;


The above two lines of code would do the same thing. += is a common operator in PC based languages, but I only learned it was supported in SCL in Siemens relatively last month. One of the posts in that thread said it was new in v15, so I guess that could be why it is new to everybody.
 
tag3 += tag4;
tag3 := tag3 + tag4;


The above two lines of code would do the same thing. += is a common operator in PC based languages, but I only learned it was supported in SCL in Siemens relatively last month. One of the posts in that thread said it was new in v15, so I guess that could be why it is new to everybody.

(I think this was written in V14. I had to "update" it to open it.)


This was my guess as well, but why would a person do the same thing two ways in the same operation?

If I were to like += for the brevity of it, and let's not leave out the fact that it isn't documented...then why would I then use x:= x+y on the very next line?

I assumed the whole project was written by a PC programmer. It is very PC like and mostly in SCL.

They had years to write and patch this monster and I have days to explain it all in "plain English" to non programmers to allow them to understand why it occasionally doesn't do what they think it should do.

What Joy.

Only STL written by Germans could be more fun.

Thanks to all who responded.
 
I was surprised too when I noticed it. I love it.
Now we just need ++i and i++ :)

Other operators:
i -= 1;
i := i - 1;

i *= 2;
i := i * 2;

i /= 3;
i := i / 3;

I usually don't use these if I'm writing code for others, but when I'm writing internal TCP comms blocks or the likes, shorthand it is!
 
Now we just need ++i and i++ :)


I was thinking the same thing, but I've also heard that they're generally considered poor form in most of the modern languages these days. I think it is partly due to the fact that they can cause troubleshooting headaches when trying to read code and figure out what it does when the variable changes, and partly due to the fact that OOP means that indexing through arrays is old hat anyway.
 
The confusion in the 1st posts shows to me why it is a bad idea with this += nonsense.
Anything that is implied is a bad thing.
Better to spell it out.

I am ok with either but not both. Consistency is a peeve of mine.

I would rather not see anything in the program that is not documented.
What are they really saving with this anyway?
 
This is where computer programmers differ from PLC programmers...

Not true, lots of PLC programs are also full of spaghetti and weird obtuse indirect addressing and loops that do nothing.

I just spent 30 minutes looking at a weird if then nested inside an if then else if inside a loop that after all the variables were tracked down and understood, did nothing at all.

It is not all documented and easy to follow.

Not sure which camp is worse about comments and documenting the code in the code, I don't see much of it in either camp.

But for really opaque code, nobody beats the Germans.
 

Similar Topics

Hello nice to meet you, im new in here, I'm currently trying to convert code written in STL for a S7-400 to SCL for an S7-1500, because when i run...
Replies
5
Views
267
Hi everyone, I am new to this amazing world of PLC, well... I mean, in practice, since I already knew electronics, programming languages, IT, and...
Replies
7
Views
608
Hi all, This is my first post; I am new to PLC Controls stuff and English is not my native language, so I apologize in advance if something is...
Replies
4
Views
490
Hi! I am working on a project were we will be replacing an 300 CPU with a 1500 CPU and we are working on migrating / converting code. There is a...
Replies
9
Views
1,026
Hello everyone, friends. I need help with something related to SCL. In a FB, I need to copy the value in the DB to the DB at another address. I...
Replies
3
Views
1,350
Back
Top Bottom