16 hours ago16 hr Hi - trying to find out if there is a way to do a nested "if". In other words - I need the "if" to be inside the "Then" and the "Else" (I need to do this for a variable test as part of a program that tests status of several devices). I cannot add this test as part of the first "if" because then the "else" will fire and run those commands - though I need the same "if" within the else.Basically the code would be:IF status Device_X is offAND status Device_Y is offAND status Device_Z is offThen if variable Poll_Running =1 Then do somethingElse if variable Poll_Running =1 then do something differentBottom line - if the Poll_Running variable is not 1 - then I don't want anything to happen irrespective of the state of the devices.Any thoughts?
16 hours ago16 hr If I understand your needs, Create the variable Poll_running as an integer type and add it to the If. They do not cause a program to trigger like state type. Edited 16 hours ago16 hr by hart2hart
16 hours ago16 hr You can't have an IF statement in the THEN or ELSE statementYou can split it up into two programs Edited 16 hours ago16 hr by Techman
12 hours ago12 hr There is a nasty way of doing most of these using "repeat while" construct.If whateverThen do something Repeat While 'lamp' < 1% do somethingElse set 'lamp' = 100% Repeat for 1 times do anotherthingElse --Of course you can set a variable before the repeat while loop and then modify it in the loop.Dirty but it can work in most cases.Multiple Case type constructs can be built by terminating each Case with a line: Stop 'ThisProgram' .Note: Repeat For X times is a program logical syntax error. 'Repeat 1 times' means no repeat at all. Should have been named: 'Execute for 1 times'.
4 hours ago4 hr 11 hours ago, SMonk said:trying to find out if there is a way to do a nested "if"@hart2hart 's solution should work in your particular situation. If, for some reason, you cannot change the variable to an "integer" type, then allow me to expand upon @Techman 's suggestion to try a second program:if IF status Device_X is offAND status Device_Y is offAND status Device_Z is offthen run a second program (if path)Second program (disabled):if variable Poll_Running =1then do something
13 minutes ago13 min Author 16 hours ago, hart2hart said:If I understand your needs, Create the variable Poll_running as an integer type and add it to the If. They do not cause a program to trigger like state type.I originally thought about this (the Poll_Running variable is already an integer - set by a prior program). Unfortunately if I add th ePoll_Running variabel to the if clause - then when this runs if Poll_Running is "not" 1 - then it will default to the "else" clause when triggered - which I do not want it to do.
9 minutes ago9 min Author 4 hours ago, oberkc said:@hart2hart 's solution should work in your particular situation. If, for some reason, you cannot change the variable to an "integer" type, then allow me to expand upon @Techman 's suggestion to try a second program:if IF status Device_X is offAND status Device_Y is offAND status Device_Z is offthen run a second program (if path)Second program (disabled):if variable Poll_Running =1then do somethingYes - this is the approach I decide to try out. It does work - but it's just a lot of programs (as I need to do this for many rooms (one program per room, and one line of the if statement for each device in a room) - hence looking to try and reduce number of programs by finding some potential alternative. 12 hours ago, larryllix said:There is a nasty way of doing most of these using "repeat while" construct.If whateverThendo somethingRepeat While 'lamp' < 1%do somethingElseset 'lamp' = 100%Repeat for 1 timesdo anotherthingElse--Of course you can set a variable before the repeat while loop and then modify it in the loop.Dirty but it can work in most cases.Multiple Case type constructs can be built by terminating each Case with a line:Stop 'ThisProgram' .Note: Repeat For X times is a program logical syntax error. 'Repeat 1 times' means no repeat at all. Should have been named:'Execute for 1 times'.This is very interesting - I have never used the "Repeat While" function - I will investigate that. This "could" be the solution to reducing the number of programs significantly. I'll let you know how it goes.
5 minutes ago5 min The second program method is the way I do it. The second program is a disabled program that only gets run by the first program. I even name it starting with DNE (for Do Not Enable) to make it stand out.
Create an account or sign in to comment