Help - Search - Members - Calendar
Full Version: question about boolean and integer
Forums.MrPLC.com > PLCs and Supporting Devices > Omron > CX-Supervisor
biglam106
hi every body !
i have a problem
i don't understand this code ( demos files " bakery" )

if FlourTank < 100 && !MoveMan then
MoveMan = 1
endif

if MoveMan then
if MoveMan < 5 then
MoveMan = MoveMan + 1
else
MoveMan = 1
FlourTank = FlourTank + 10
endif

my question is :
1. MoveMan = integer ( 1 to 10 ) and ( ! = not ) therefore the code "!MoveMan" = what's this ?

2.this code follow :

if FlourTank < 100 && !MoveMan then
MoveMan = 1
value = what's this ( boolean or integer )

3 this code follow :

if TankOpen && FlourTank then
MillerOpen = FALSE
if Miller < 100 then
FlourTank = FlourTank - 5
Miller = Miller + 5
else
TankOpen = FALSE
endif
else
TankOpen = FALSE
endif

- tankopen = boolean
- flourtank = integer
=> why to use " TankOpen && FlourTank " therefore what is new value of the expression ?

please help me !
thank for reading
looking forward answering
Berti Baker
Hi Biglam,

I think I can see your confusion - all about mixing boolean expressions with integer operands. Hopefully I can help it make sense wink.gif

Firstly "!MoveMan" is just a shorter way of saying "!MoveMan == TRUE" or rather "MoveMan != FALSE". Now recognise that Boolean "FALSE" is always value 0, and Boolean "TRUE" is anything that is not 0 (although traditionally TRUE is 1, or -1, or 0xFFFF). So in psuedo code this line means "If the flour tank is not full, and the Man is not moving then start moving the Man"

Actually there's the same issue later with the line "IF MoveMan THEN..." which is again shorthand for "IF MoveMan == TRUE THEN..." or rather "IF MoveMan != FALSE THEN...". Basically meaning "if the man is moving then..."

So any integer can be used as a boolean expression (or with Boolean operators) where zero value means FALSE, or any other value evaluates to TRUE. (Why didn't I just say that! blink.gif )

The same for "TankOpen && FlourTank" which again really means "TankOpen && (FlourTank != 0)" i.e. "if the valve is open, and there is flour in the tank..."

Even more confused or does that sort it?
Regards,
Bertie
Sleepy Wombat
Good response there Berti... and yes you are absolutely correct...
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.