How to escape multi levels of IF statements?
Repeat
if routineA
if routineB
if ReadKeyPadA > 0
spk.beep(19, 3000, 50)
if PasswordCheck == true
if doorpos == closed '<<<<<<<<<<<
MaxSpeed := MaxSpeedOpen
newpos := oPos
doorpos := open
spk.beep(19, 2500, 50)
repeat while ReadKeyPadA > 0 'stay here until button released
waitcnt(20_000_000 + cnt)
if doorpos == open '<<<<<<<<<<<
MaxSpeed := MaxSpeedClose
newpos := cPos
doorpos := closed
spk.beep(19, 2500, 200)
repeat while ReadKeyPadA > 0 'stay here until button released
waitcnt(20_000_000 + cnt)
In the code above, if doorpos = closed, then when it gets to the next 'if doorpos = open', then the whole block cancels itself out, as the next if section resets the parameters back where they were. The solution I can use is to read the device twice like below:
Repeat
if ReadKeyPadA > 0
spk.beep(19, 3000, 50)
if PasswordCheck == true
if doorpos == closed '<<<<<<<<<<<
MaxSpeed := MaxSpeedOpen
newpos := oPos
doorpos := open
spk.beep(19, 2500, 50)
repeat while ReadKeyPadA > 0 'stay here until button released
waitcnt(20_000_000 + cnt)
if ReadKeyPadA > 0
spk.beep(19, 3000, 50)
if PasswordCheck == true
if doorpos == open '<<<<<<<<<<<
MaxSpeed := MaxSpeedClose
newpos := cPos
doorpos := closed
spk.beep(19, 2500, 200)
repeat while ReadKeyPadA > 0 'stay here until button released
waitcnt(20_000_000 + cnt)
But this wastes time and has other implications, but it does work to a degree.
Can anyone suggest a method to back out of the entire if ReadKeyPadA > 0 section if the first section is TRUE, avoiding it canceling itself in the subsequent section?
Thanks

Comments
-Phil
In the first if doorpos == closed, if it IS closed then the line below it makes it become doorpos := open, then when it gets to the next if doorpos == open, it puts the variable back where it was, canceling the whole thing out.
Maybe I am missing your point?
-Phil
Post Edited (Phil Pilgrim (PhiPi)) : 1/27/2009 9:22:33 PM GMT
I am sure there must be a more complex way to accomplish this? [noparse]:)[/noparse]
Thanks!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔