Shop OBEX P1 Docs P2 Docs Learn Events
Just can't figure out what is wrong with this code...snippit — Parallax Forums

Just can't figure out what is wrong with this code...snippit

denodeno Posts: 242
edited 2006-06-26 20:28 in BASIC Stamp
I keep getting an error message on the following code, and I am sure it is something simple that I am overlooking...

··· SELECT gallons_of_water
····· CASE > 7 AND· <= 49
······· average_error_of_sensor = 17
····· CASE > 49 AND· <= 109
······· average_error_of_sensor = 31
····· CASE > 109 AND· <=186
······· average_error_of_sensor = 21
····· CASE > 186 AND <= 255
······· average_error_of_sensor = 11
··· ENDSELECT

Thanks to all...Deno

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-06-25 00:41
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
     
    gallons_of_water VAR Byte
    average_error_of_sensor VAR Byte
     
        SELECT gallons_of_water
          CASE > 7, <= 49
            average_error_of_sensor = 17
          CASE > 49, <= 109
            average_error_of_sensor = 31
          CASE > 109, <=186
            average_error_of_sensor = 21
          CASE > 186, <= 255
            average_error_of_sensor = 11
        ENDSELECT
    
  • willthiswork89willthiswork89 Posts: 359
    edited 2006-06-25 01:37
    there he fixed it or you could do

    case > 7 and CASE <= 49

    you have to supply another variable because the AND thinks your comparing more then one variable at a time.
  • KatyBriKatyBri Posts: 171
    edited 2006-06-25 01:42
    After reading this thread, I have a question.

    The help section in the STAMP IDE V2.1 shows AND as an acceptable Conditional Logic Operator. Why can't it be used? Is the table in the IDE help in error?
  • willthiswork89willthiswork89 Posts: 359
    edited 2006-06-25 03:23
    and i suppose would be considered a logic operator because in order for the If to be true both conditions must be true. so it is considered a logical operator because it helps with distinguishing things that need two variables true or the entire statement if false and wont be executed. correct me if im wrong!
  • SSteveSSteve Posts: 808
    edited 2006-06-26 20:28
    Use the "TO" operator for ranges. Also, once you get to the second CASE, you don't need to test for conditions that were true in an earlier CASE. This will work:
    SELECT gallons_of_water
        CASE 8 TO 49
            average_error_of_sensor = 17
        CASE <= 109
            average_error_of_sensor = 31
        CASE <=186
            average_error_of_sensor = 21
        CASE <= 255
            average_error_of_sensor = 11
    ENDSELECT
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows

    links:
    My band's website
    Our album on the iTunes Music Store
Sign In or Register to comment.