Join us today!
[Solved] instruction increment a variable by one, var +=1;?
Hello,
I want to increment or decrement a variable type INT by one,
this instruction works for me in Tia Portal, in TwinCAT how would it be?..
PROGRAM MAIN
VAR
var : INT;
END_VAR
var +=1;
https://github.com/runtimevic
https://github.com/TcMotion
https://www.youtube.com/playlist?list=PLEfi_hUmmSjFpfdJ6yw3B9yj7dWHYkHmQ
https://github.com/VisualPLC
Hi,
To increase by 1:
var := var + 1;
To decrease by 1:
var := var - 1;
I wouldn't recommend using 'var' as your variable name since it's a keyword in TwinCAT 3.
In case you want to say thank you !)
We'd be very grateful if you could share this community with your colleagues and friends. You can also buy us a coffee to keep us fueled 😊 This is the best way to say thank you to this project and support your community.
twinControls - https://twincontrols.com/
Isn't there a more compact instruction?
Variable Name "var" was an example without taking anything into account...
Thanks.
https://github.com/runtimevic
https://github.com/TcMotion
https://www.youtube.com/playlist?list=PLEfi_hUmmSjFpfdJ6yw3B9yj7dWHYkHmQ
https://github.com/VisualPLC
If you'd like you can create a function to do that as well.
FUNCTION F_IncreaseBy:
FUNCTION F_IncreaseBy : BOOL VAR_INPUT nNumber :REFERENCE TO INT ; nIncreaseBy : INT; END_VAR VAR END_VAR nNumber := nNumber + nIncreaseBy; F_IncreaseBy := TRUE;
MAIN:
PROGRAM MAIN VAR nNumber : INT; END_VAR F_IncreaseBy(nNumber,2); // number, increase amount
In case you want to say thank you !)
We'd be very grateful if you could share this community with your colleagues and friends. You can also buy us a coffee to keep us fueled 😊 This is the best way to say thank you to this project and support your community.
twinControls - https://twincontrols.com/
I'd love to have a full set of assignment operators in ST, plus pre- and post- increment/decrement. But alas, 'tis not to be. I sometimes find myself typing them in by mistake then gritting my teeth as the compile errors stack up.
- 17 Forums
- 265 Topics
- 932 Posts
- 2 Online
- 689 Members