Shop OBEX P1 Docs P2 Docs Learn Events
SELECT.....CASE Question — Parallax Forums

SELECT.....CASE Question

D FaustD Faust Posts: 608
edited 2007-06-27 18:44 in BASIC Stamp
Is there a symbol that can be used as an "OR" in the statement: "CASE %1100 OR %1000" or can only one value be placed as a condition for CASE?· Thank you in advance.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
D Faust

Comments

  • NewzedNewzed Posts: 2,503
    edited 2007-06-27 12:45
    Did you know that SELECT/CASE statements use more bytes than IF/THEN statements?

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Yesterday is history, tomorrow is a mystery, and today is a gift.

    That is why they call it the present.

    Don't have VGA?
    Newzed@aol.com
    ·
  • Mike GreenMike Green Posts: 23,101
    edited 2007-06-27 12:45
    "CASE %1100, %1000" works
  • D FaustD Faust Posts: 608
    edited 2007-06-27 12:50
    Thanks Mike.
    Is the difference signifcant/would a select...case command be better than a bunch of "IF variable = ?"? By a bunch I mean 3 or 4. Where can I find the amount of space that a command takes up?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    D Faust
  • Mike GreenMike Green Posts: 23,101
    edited 2007-06-27 12:54
    I'm not sure if it will answer this specific question, but www.emesystems.com has all kinds of information on PBasic and its use.
  • NewzedNewzed Posts: 2,503
    edited 2007-06-27 13:02
    Enter your SELECT/CASE statements, then look at the Memory Map to see how many bytes you have used.· Replace your SELECT/CASE with IF/THEN statements and again check the Memory Map.· You can then tell which procedure uses the least bytes.

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Yesterday is history, tomorrow is a mystery, and today is a gift.

    That is why they call it the present.

    Don't have VGA?
    Newzed@aol.com
    ·
  • Tracy AllenTracy Allen Posts: 6,667
    edited 2007-06-27 16:14
    PBASIC actually resolves the SELECT CASE statements into IF-THEN statements. This page in particular shows how the IDE manages it:
    www.emesys.com/BS2pbasic25.htm
    It can be efficient and certainly easier to read when written as SELECT CASE instead of IF THEN. One caveat. It is possible to put an expression in the SELECT (e.g. SELECT x - 48), but avoid doing so, particularly if there are several CASEs, because PBASIC will parse out multiple copies of the expression. It's better to write, say, x=x-48 : SELECT x : ...

    The manual has lots of examples on how to construct the conditional. You can have things like,
    CASE %1100, %1000
    ' ...
    CASE 2 TO 7, >=%1101
    ' ...
    CASE ELSE
    ' ...

    The conditionals (as opposed to expressions) are tokenized quite efficiently.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • D FaustD Faust Posts: 608
    edited 2007-06-27 17:36
    So, really it is no better to use a series of IF..THEN statements than a Select...Case Statement because PBASIC breaks it down into if...then statements anyway, right?
    Also, thank you for answering my question so quickly.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    D Faust
  • D FaustD Faust Posts: 608
    edited 2007-06-27 18:44
    In "case"lol.gif· anybody wants to know I ran a test(using memory map), and a select...case statement with four cases takes up exactly as much eeprom as the four If...then statements.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    D Faust
Sign In or Register to comment.