Forums.MrPLC.com: question about boolean and integer - Forums.MrPLC.com

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

question about boolean and integer how to use this code Rate Topic: -----

#1
User is offline   biglam106 

  • Sparky
  • PipPipPip
  • Group: MrPLC Member
  • Posts: 17
  • Joined: 04-March 09
  • Country:Vietnam
    Vietnam
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

This post has been edited by biglam106: 19 August 2009 - 12:54 PM

UNIVERSITY OF TECHNICAL EDUCATION HCM CITY
TO BE OR NOT TO BE
0

#2
User is offline   Berti Baker 

  • Sparky
  • PipPipPip
  • Group: MrPLC Member
  • Posts: 220
  • Joined: 26-July 06
  • Country:United Kingdom
    United Kingdom
Hi Biglam,

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

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! :-0 )

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

This post has been edited by Berti Baker: 29 August 2009 - 10:51 AM

0

#3
User is offline   Sleepy Wombat 

  • Controls Engineer
  • Group: MrPLC Admin
  • Posts: 1,940
  • Joined: 09-October 03
  • Gender:Male
  • Location:Sydney, NSW
  • Country:Australia
    Australia
Good response there Berti... and yes you are absolutely correct...
www.dexa.com.au - Design Engineering Xtreme Automation - DEXA Pty Ltd ** Automating the World Around You **
www.wi-count.com.au - WI-COUNT Wireless Counting Technologies ** Wireless People Counting **




0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users