Example of what I am doing. Can this be simplified, especially if I am using more variables.
IF PVL.dut_PonyGroupSettings.ProcessVariable_ci = GVL.c_ai_DischargePressure OR PVL.dut_MidGroupSettings.ProcessVariable_ci = GVL.c_ai_DischargePressure OR PVL.dut_MainGroupSettings.ProcessVariable_ci = GVL.c_ai_DischargePressure OR PVL.dut_HFGroupSettings.ProcessVariable_ci = GVL.c_ai_DischargePressure THEN DoTask := TRUE;END_IF
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This could even be improved upon readability wise;
xDoTask := xVar1 OR xVar2 OR xVar3 OR xVar4;
But the original question was;
IF PVL.dut_PonyGroupSettings.ProcessVariable_ci = GVL.c_ai_DischargePressure ORPVL.dut_MidGroupSettings.ProcessVariable_ci = GVL.c_ai_DischargePressure OR PVL.dut_MainGroupSettings.ProcessVariable_ci = GVL.c_ai_DischargePressure OR PVL.dut_HFGroupSettings.ProcessVariable_ci = GVL.c_ai_DischargePressure THEN DoTask := TRUE;END_IF
which could be rewritten for better readability into
In my opinion, "smart code" should NOT be as compact as possible, but it should be READABLE, especially at 03:00 saturday night!
You could try to rework the code into a CASE statement, but since it uses all kinds of GVL's that isn't simply possible.
Last edit: hermsen 2022-04-29
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you kindly for your time I, I like the method you prescribe! But it sounds like its not possible to compare multiple variables collectively against one.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ah the funny thing is I am turning everything into Arrays anyways for other purposes! Reading through this there were a couple of new things I haven't seen, I looked them up and learned some new functions. I will probably end up doing something like the first example you gave. Thank you so much for your time and detailing. I am learning a lot from all the help!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just steer clear of writing "too compact" code and prefer readability over "performance". Usually "performance" isn't an issue nowadays (unless it is but then you should focus on low hanging fruit first).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Example of what I am doing. Can this be simplified, especially if I am using more variables.
I would write each OR statement under the other. For example;
or you can create an action with FBD language then you can see this with a box view.
Last edit: BY 2022-04-29
Much cleaner thank you for the tip!
This could even be improved upon readability wise;
But the original question was;
which could be rewritten for better readability into
If you mix 1 and 2 you get;
In my opinion, "smart code" should NOT be as compact as possible, but it should be READABLE, especially at 03:00 saturday night!
You could try to rework the code into a CASE statement, but since it uses all kinds of GVL's that isn't simply possible.
Last edit: hermsen 2022-04-29
Maybe there was to much garbage, the variables being INT.
EDIT!!!!
Last edit: loganr4l 2022-04-29
Thank you kindly for your time I, I like the method you prescribe! But it sounds like its not possible to compare multiple variables collectively against one.
If you want your variable (Integer types only!) to be assessed against a value range, you could use a CASE OF Statement;
Last edit: hermsen 2022-04-29
Could be rewritten into;
DoTask := (iVar1 = iVar10) ;
Albeit DoTask is now continously evaluated.
Last edit: hermsen 2022-04-29
oh man i messed up, I edited my mistake
Don't worry, just don't use such code in your program ;-)
I am sure you are busy, and I thanks for your help and your time good sir.
You can build a list of pointers (or interfaces, if you use function blocks), and then batch process it.
This is less readable than yours, but is more flexible (it becomes more and more readable the more conditions you have).
Related
Talk.ru: 1
Talk.ru: 2
Talk.ru: 3
Ah the funny thing is I am turning everything into Arrays anyways for other purposes! Reading through this there were a couple of new things I haven't seen, I looked them up and learned some new functions. I will probably end up doing something like the first example you gave. Thank you so much for your time and detailing. I am learning a lot from all the help!
Just steer clear of writing "too compact" code and prefer readability over "performance". Usually "performance" isn't an issue nowadays (unless it is but then you should focus on low hanging fruit first).