Shop OBEX P1 Docs P2 Docs Learn Events
Mutiple "OR" in case statement .. my find of the day.. — Parallax Forums

Mutiple "OR" in case statement .. my find of the day..

OzStampOzStamp Posts: 377
edited 2008-03-10 11:03 in Propeller 1
Hi Fellow Proppers.

Thought I share this with you all..

The manual to my knowledge does not mention· that the below is actually possible.
Tested it and seems to work..

Lets say I have 4 values that tell me an output needs to come on.
I picked on the values 1,3,24 and 96· ( stored in a variable eg called "value"i)
Any other value we want the output to be off..

The below very simple case works well multiple "OR" check

··· Case value
···· 1,3,24,96 ·:· outa[noparse][[/noparse]16]:=1
·····other······ ·: outa[noparse][[/noparse]16]:= 0


Cheers·· ron mel oz...

Post Edited (OzStamp) : 3/10/2008 4:52:32 AM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-10 04:46
    The manual does show it. It is really handy as you've noticed.

    In your case, the 2nd "outa[noparse][[/noparse] 16 ] := 1" should be "outa[noparse][[/noparse] 16 ] := 0"
  • OzStampOzStamp Posts: 377
    edited 2008-03-10 04:53
    Hi Mike
    I corrected my type error.

    The manual shows only 2 values as an OR .
    On page 172

    It sure is a handy instruction ...
    Thnx Mike for jumping re the error..

    Rgds Ron Mel OZ
  • deSilvadeSilva Posts: 2,967
    edited 2008-03-10 06:06
    Hippiy discussed this syntax in the Tips&Tricks thread for LOOKUP. Note that LOOKUP, CASE and LOOKDOWN are very similar in many respects.

    The allowed Syntax for all is:
    "A","D",255, "abcde", 0..9:
  • OzStampOzStamp Posts: 377
    edited 2008-03-10 07:17
    Hi DeSilva.

    There is so much info...
    all over the place... finding it sometimes takes longer than actually doing it sometimes..

    Some info is in places you would not expect it to be...

    I will try and find that link from Hippy and print it all out and put in my "FOUND TREASURES FOLDER"

    Cheers Ron Mel OZ...
  • QuattroRS4QuattroRS4 Posts: 916
    edited 2008-03-10 08:53
    Nice one Ron ..this will help tidy a bit of code for me ..

    Regards,
    John

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Necessity is the mother of invention'
  • deSilvadeSilva Posts: 2,967
    edited 2008-03-10 09:23
    To be honest it is all in the Manual and at the right place, in this case it says:

    "MatchExpression is a singular or comma-delimited set of value- and/or range expressions,
    to compare CaseExpression against. Each MatchExpression must be followed by a colon ([noparse]:)[/noparse]."

    The bad thing is, that many of our comrades need EXAMPLES to understand what that could mean, and examples - indeed - are spread around.

    The other bad thing is, that the Manual is not very systematic. It pretends this by many repetetions, especially in chapters 4 and 5 ("Flags") But here were errors introduced by copy and past...So MatchExpresion is not "exactly" what this definition says smile.gif

    And it is always also needed to look into the ERRATA!

    Well, Hippy did not "found" it - he knew it before as most of us - but he (and Phil) started the "systematic" view of it, as the tricky part is the "string" denotation allowed there, in LOOKUP, and in DAT presets...

    Post Edited (deSilva) : 3/10/2008 9:28:19 AM GMT
  • OzStampOzStamp Posts: 377
    edited 2008-03-10 09:57
    Hi John and other Fellow Proppers

    For you and people that understand of how a PLC is programmed this code as posted above knocks
    something right on the head LOGIC WISE very powerfull.
    The value in the "OR" are the conditions that resolve to an "ON condition"
    ..
    I have posted the attached screenshot before and suggested soembody knocks up a PROP LADDER LOGIC package.
    Funny enough not many people responded..

    See picture attached.. hopefully it explains it all.

    De SILVA.. there is nothing like having more examples.
    That's why I thought we post it here..

    Cheers Ron Mel OZ.
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-03-10 10:04
    What does the package have to do?
  • deSilvadeSilva Posts: 2,967
    edited 2008-03-10 10:23
    I think one should take a kind of "schematic editor"
    This one will produce (hopefully) some intermediate code.

    We can then write a converter which produces some (machine) code out of it.

    This will not be too difficult... 12 Inputs, 12 outputs
    The propagation time will be <100µs for 4 or 5 layers

    In SPIN however it will be around 10 ms/layer..
  • QuattroRS4QuattroRS4 Posts: 916
    edited 2008-03-10 11:03
    DeSilva - Yip its in the manual - but I suppose I had not fully appreciated it's scope - which is why , I suspect, that Ron highlighted it - I for one am glad he did.

    Probably best covered by Ron who said -

    "For you and people that understand of how a PLC is programmed this code as posted above knocks
    something right on the head LOGIC WISE very powerfull.
    The value in the "OR" are the conditions that resolve to an "ON condition
    "

    For people that cut their teeth on and before PLC's - this is noteworthy .. I have horrid memories of writing conditional sequences for PLC's on old machinery - now just throw it out and 'Propify' it ..


    Regards,
    John Twomey

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Necessity is the mother of invention'
Sign In or Register to comment.