Shop OBEX P1 Docs P2 Docs Learn Events
Use LOOKUP and LOOKDOWN Command instead of IF THEN Statements — Parallax Forums

Use LOOKUP and LOOKDOWN Command instead of IF THEN Statements

sam_sam_samsam_sam_sam Posts: 2,286
edited 2007-08-10 22:38 in General Discussion
Hi EveryOne

I want to learn more about using diffrent commands any idea.gifs

I have a project that·I have put on hold for awhile because· of·not know how to do away so many IF THEN Statements


This what i want to do is this

Hours of·Sun Light
···············IF hrs = $10 AND mins = $00 THEN· =· Leave Out side light·ON hours·for·8 hrs and·00 mins
···············IF hrs = $10 AND mins = $30 THEN· =· Leave Out side light·ON hours for·7 hrs·and 30 mins··
···············IF hrs = $11 AND mins = $00 THEN· =· Leave Out side light·ON hours for·7· hrs·and·00 mins

Can some one·give me an example of how to do this with the three above


···············IF hrs = $11 AND mins = $30 THEN· =· Leave Out side light·ON hours·for·6··hrs·and·30 mins
···············IF hrs = $12 AND mins = $00 THEN· =· Leave Out side light·ON hours·for·6· hrs·and·00 mins····
···············IF hrs = $12 AND mins = $30 THEN· =· Leave Out side light·ON hours·for·5· hrs·and·30 mins
·············· IF hrs = $13 AND mins = $00 THEN· =· Leave Out side light·ON hours·for·5· hrs·and·00 mins
·············· IF hrs = $13 AND mins = $30 THEN· =· Leave Out side light·ON hours·for·4· hrs·and·30 mins
·············· IF hrs = $14 AND mins = $00 THEN· =· Leave Out side light·ON hours·for·4· hrs·and·00 mins
·
I would like to learn how to do away with all of the IF THEN Statement

This is what i did was use the Select and case command but can only do the hrs or mins but not both

SELECT hrs
·CASE $10
·GOTO Timer1
·CASE $11
·GOTO Timer2
·CASE $12
·GOTO Timer3
·CASE $13
·GOTO Timer4
·CASE $14
·GOTO Timer5
·ENDSELECT

·

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·idea.gif·that you may have and all of your time finding them

·
·
·
·
Sam

Post Edited (sam_sam_sam) : 8/9/2007 3:23:23 AM GMT

Comments

  • D FaustD Faust Posts: 608
    edited 2007-08-09 00:38
    It would be easier if you combined hrs and minutes into one variable.· That said here is what I would do:
    DO
    SELECT mins
     CASE $30       'Sort by minute value
      GOSUB half
     CASE $00
      GOSUB oclock
    ENDSELECT                                 'Based on selcted subnumber run proper routine
    ON subnumber GOSUB t800, t730, t700, t630, t600, t530, t500, t430, t400
    LOOP
     
    half:                                          
    LOOKDOWN hrs, [noparse][[/noparse]$10, $11, $12, $13], looknum 'minute value of 30 is known, compare hour # and 
    LOOKUP looknum, [noparse][[/noparse]1, 3, 5, 7], subnumber     'assign value to looknum. ie: $11 = 1, or $13 = 3 
    RETURN                                      'Based on looknum select subroutine # ie: 3 >> 7 
                                                'or 1>>3
     
    oclock:
    LOOKDOWN hrs, [noparse][[/noparse]$10, $11, $12, $13, $14], looknum
    LOOKUP looknum, [noparse][[/noparse]0, 2, 4, 6, 8,], subnumber
    RETURN
     
    
    

    I don't mean to brag, but this isn't all that hard to learn,(I did·it tonight)·especially with the help file (check out the example code).· I think this covers all of it.· Feel free to ask questions, but look at the help file first.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
     
    This_Thread     VAR       Word
    My_Question     VAR       Word
    Your_Question   VAR       Word
    Cool_Thing      VAR       Word
    Abandoned       VAR       Word
     
    DO
     IF This_Thread = My_Question THEN
      DEBUG "Thank You For Your Time!"
     ELSEIF This_Thread = Your_Question THEN
      DEBUG "I Hope This Helps."
     ELSEIF This_Thread = Cool_Thing
      DEBUG "AWESOME!!"
     ELSE
      DEBUG "What Am I Supposed To Do?"
     ENDIF
     DEBUG "D Faust"
    LOOP UNTIL This_Thread = Abandoned
    


    ·
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2007-08-09 01:46
    D Faust
    Thank You For your help with this
    This an example that i can understand
    I did look at the· on line help first·but i did not understand the example that where given

    It would be easier if you combined hrs and minutes into one variable.· That said here is what I would do:
    DO
    SELECT mins
     CASE $30       'Sort by minute value
      GOSUB half
     CASE $00
      GOSUB oclock
    ENDSELECT                                 'Based on selcted subnumber run proper routine
    ON subnumber GOSUB t800, t730, t700, t630, t600, t530, t500, t430, t400
    LOOP
     
    half:                                          
    LOOKDOWN hrs, [noparse][[/noparse]$10, $11, $12, $13], looknum 'minute value of 30 is known, compare hour # and 
    LOOKUP looknum, [noparse][[/noparse]1, 3, 5, 7], subnumber     'assign value to looknum. ie: $11 = 1, or $13 = 3 
    RETURN                                      'Based on looknum select subroutine # ie: 3 >> 7 
                                                'or 1>>3
     
    oclock:
    LOOKDOWN hrs, [noparse][[/noparse]$10, $11, $12, $13, $14], looknum
    LOOKUP looknum, [noparse][[/noparse]0, 2, 4, 6, 8,], subnumber
    RETURN
     
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 8/9/2007 1:56:48 AM GMT
  • D FaustD Faust Posts: 608
    edited 2007-08-09 13:55
    You are very welcome. FYI, I ran a test, and the Case...Select statement uses up more eeprom space. As I said earlier, if you combine the two the select...case at the top could be eliminated. I would make the variable in tenths of an hr, so $10 and $30 = $105. You can't use just hrs, because od decimal point restrictions.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    LOOKDOWN ThisThread, [noparse][[/noparse]Your_?, My_?, Cool_Thing], looknum
    LOOKUP looknum, [noparse][[/noparse]1, 2, 3], subnum
    ON subnum GOTO Hope_this_helps, Thanks!, WOW!!
    END 
    
  • BrightTassyBrightTassy Posts: 1
    edited 2007-08-10 15:35
    do not think inside the box****************888888888888888888888888888888

    Pin U will get

    you will get pin ned

    infinitys endless journeys 888888888888888888 sideways
  • D FaustD Faust Posts: 608
    edited 2007-08-10 16:21
    What???· I get that the 8's are infinities, and you said to think outside the box, but what does that have to do with the lookup and down commands?· What do you mean by:
    BrightTassy said...
    Pin U will get

    you will get pin ned
    I am happy to help you with lookup/down commands, but I am not sure what you mean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    LOOKDOWN ThisThread, [noparse][[/noparse]Your_?, My_?, Cool_Thing], looknum
    LOOKUP looknum, [noparse][[/noparse]1, 2, 3], subnum
    ON subnum GOTO Hope_this_helps, Thanks!, WOW!!
    END 
    
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2007-08-10 20:51
    · D Faust

    Please explane this more for me

    I would make the variable in tenths of an hr, so $10 and $30 = $105.

    [noparse][[/noparse]How dose this· =·($105) ] = 10 and $30


    ·



    ·



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
  • D FaustD Faust Posts: 608
    edited 2007-08-10 22:38
    What i meant was 105 without the $.· Because 10 hrs = 100 / 10 hrs and .5 hr = 5 /10 hrs.· Hope I am clear.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    LOOKDOWN ThisThread, [noparse][[/noparse]Your_?, My_?, Cool_Thing], looknum
    LOOKUP looknum, [noparse][[/noparse]1, 2, 3], subnum
    ON subnum GOTO Hope_this_helps, Thanks!, WOW!!
    END 
    
Sign In or Register to comment.