Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / using case to toggle siren

Author
Message
fllwthewolves
13
Years of Service
User Offline
Joined: 4th Sep 2011
Location:
Posted: 25th Mar 2012 19:52
But it wont work...




What happens is when i press the upkey it will change s to 1 but then upon hitting it again it will not change s back to 0.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 25th Mar 2012 20:05
Change:



To:



fllwthewolves
13
Years of Service
User Offline
Joined: 4th Sep 2011
Location:
Posted: 25th Mar 2012 20:13
Well it worked, thanks. but would you mind surrendering, for future reference, why it worked and what i had diddnt. or is it just one of those things...
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 25th Mar 2012 21:32
well in your version, it's possible for both IF statements to be true, which will make the value of S flip/flop from 1 to 0 then back to 1 again..




I suspect, you might have been thinking that the second IF/ENDIF will be ignored when the first IF/ENDIF executes. Not the case, the language will execute them all, unless we tell it skip past or create a more complex decision.

IF/ELSE/ENDIF allows us to make a decision that has two path ways for the program to execute. It executes between the IF / ELSE statements when the comparison is TRUE, otherwise it'll execute the code between the ELSE/ENDIF




If all you want to do is flip the value of S, you can use subtraction to do that for you.

S = 1 - S

Now we're assuming S is either 0 or 1. When it's zero, S = 1-0, when it's 1 , S = 1-1.. So it'll toggle the value between Zero / One.

fllwthewolves
13
Years of Service
User Offline
Joined: 4th Sep 2011
Location:
Posted: 25th Mar 2012 22:46
Quote: "well in your version, it's possible for both IF statements to be true, which will make the value of S flip/flop from 1 to 0 then back to 1 again.."


Oh wow, i cant believe i was over looking that lol. All that time i spent looking into case statements and trying to debug, and it was something that simple.

Quote: "If all you want to do is flip the value of S, you can use subtraction to do that for you.

S = 1 - S

Now we're assuming S is either 0 or 1. When it's zero, S = 1-0, when it's 1 , S = 1-1.. So it'll toggle the value between Zero / One."


This seems like a much better way to do it i think ill adopt it.

Thanks for all the input.

Login to post a reply

Server time is: 2024-11-23 20:21:34
Your offset time is: 2024-11-23 20:21:34