Page 1 of 1

Enter "if" based on either of two variables changing

Posted: Mon Jun 30, 2014 7:41 pm
by 00Warpig00
I'm not a programmer so this is might be rough way to ask this question not knowing the proper lingo but here goes. I would like to enter the same set of statements within an "if" based on whether either of two variables have changed in my last loop?

The best way I can think of to lay this out hopefully will give the idea. I realize the syntax is going to be wrong below. I guess that is what I am asking for. correct syntax.

Code: Select all


 if ( PreviousVariable1 != CurrentVariable1 ) or ( PreviousVariable2 != CurrentVariable2 )
     {
       do stuff
       do more stuff
       do even more stuff
     }

 PreviousVariable1 = CurrentVariable1;
 PreviousVariable2 = CurrentVariable2;

 else


hope this makes sense... Don't want run it if BOTH variables have been changed (I could use nested if's for that). Want to run that code if either of the two have changed.

Nick

Re: Enter "if" based on either of two variables changing

Posted: Mon Jun 30, 2014 8:05 pm
by rimai
It would be like this:

Code: Select all

if ( ( PreviousVariable1 != CurrentVariable1 ) || ( PreviousVariable2 != CurrentVariable2 ) )

Re: Enter "if" based on either of two variables changing

Posted: Mon Jun 30, 2014 8:14 pm
by 00Warpig00
Thanks Roberto. Will give that a try. :)

Nick

Re: Enter "if" based on either of two variables changing

Posted: Mon Jun 30, 2014 9:21 pm
by 00Warpig00
That worked a treat... Thanks again.

A while ago I set up my LED Drivers\QT\Sump Lights to be able to be masked on manually for when I am out of town and need to check the tank via webcam late at night in the hotel after a long days work. They can also be masked off manually for when I am watching a movie on the big screen with the projector. Problem is after a few movies and masking the lights off and going to bed I would often forget to remove the mask. Lights are still off early in the morning when I leave for work and the next day the tank would remained dark all day due to my forgetfulness. oops. So I added a mask timeout. I normally don't mask them off for more than 4 hours so I set a byte in memory. When I set the mask it reads the byte and sets the timeout for the byte value in minutes before assuming I forgot to turn off the mask and clearing it automatically. The timer would be calculated when the mask was set and then only. So if I had the byte set for 255 minutes when I turned the mask on the timeout was 255 minutes regardless of if I changed the byte in memory during the timer running. I decided I wanted to put the cherry on top for ultimate flexibility and be capable of changing the timer on the fly. This allowed me to do just that. :D

Thanks again,

Nick

Re: Enter "if" based on either of two variables changing

Posted: Mon Jun 30, 2014 9:32 pm
by rimai
Awesome!!!