Shop OBEX P1 Docs P2 Docs Learn Events
Select/Case — Parallax Forums

Select/Case

ArchiverArchiver Posts: 46,084
edited 2003-03-20 10:39 in General Discussion
Hi Stampers,

I really like the new commands but I think I didN't quite understand the
SELECT CASE command and the TCASE option. If someone could look at the code
below (that works fine now) and tell me if I could change the several SELECT
CASE-routines into a single bigger one by using TCASE or something. I tried
but didnot succeed either with TCASE nor with CASE. What does the second
CASE-block of a routine do when the preceeding did / didn't apply?

Thanks for your help, Uli


CODE AS FOLLOWS:

Select sensorport

case 1,3,5,7,9,11,13,15
if K_index_A = 0 then
high Bremse_A
K_index_A = 1
endif
endselect

Select sensorport

case 2,3,6,7,10,11,14,15
if K_index_B = 0 then
high Bremse_B
K_index_B = 1
endif
endselect

Select sensorport

case 0,2,4,6,8,10,12,14
K_index_A = 0
low bremse_A
endselect

Select sensorport

case 0,1,4,5,8,9,12,13
K_index_B = 0
low bremse_B

endselect


Select sensorport

case 4,5,6,7,12,13,14,15
if R_index_A = 0 then
rundenzahl_A = rundenzahl_A+1
R_index_A = 1
endif
endselect

Select sensorport

case 8 to 15
if R_index_B = 0 then
rundenzahl_B = rundenzahl_B+1
R_index_B = 1
endif
endselect

Select sensorport

case 0,1,2,3,8,9,10,11
R_index_A = 0

endselect

Select sensorport

case 0 to 7
R_index_B = 0

endselect
'debug cls
'debug? sensorport,cr
'debug? K_index_A
'debug? K_index_B
'debug? R_index_A
'debug? R_index_B
'debug cr
goto start


[noparse][[/noparse]Non-text portions of this message have been removed]

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-03-20 10:39
    Hi,

    possibly your program uses more selects than are neccessary, it
    depends on what you intend to do. Wich each new select you are
    re-reading sensorport (which may be what you intend/need to do).

    I assume sensorport ranges from 0 to 15, so you could simplify some
    of your cases to a more efficient if statement:

    select sensorport
    case 1,3,5,7,9,11,13,15

    could be replaced by

    if sensorport.bit0 = 1 'all odd values

    and

    select sensorport
    case 1,3,5,7,9,11,13,15

    could be replaced by

    if sensorport.bit0 = 0 'all even values

    The difference between case and tcase is that after a case clause
    execution continues after the endselect,
    after a Tcase execution continues after the Tcase clause possibly
    leading into a following case/tcase clause.

    Example:

    For x = 1 the following select executes actions_1 only, for x = 3
    it executes actions_2.

    select x
    case 1
    actions_1
    case <5
    actions_2
    endselect

    For x = 1 the following select executes actions_1 and actions2 as
    x is = 1 and < 5 as well, for x = 3 it executes actions_2 only.

    select x
    tcase 1
    actions_1
    case <5
    actions_2
    endselect

    regards
    Adrian
Sign In or Register to comment.