CASE min TO max

Place code snippets and demo code here
Post Reply
User avatar
Electroguard
Posts: 836
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 268 times
Been thanked: 317 times

CASE min TO max

Post by Electroguard »

If you take the time and effort to implement something CiccioCB, it obviously offers some worthwhile benefit even if that benefit is not immediately obvious to me... as with the additional CASE min TO max option.
Annex Help mentions the syntax, but doesn't explain how to use it, or give any usage limitations or constraints.
(eg: can it only be consecutive integers from min to max?)

It's just that I noticed it mentioned twice in the Change Log - "Implemented CASE min TO max" (Version 1.41 beta 3 and Version 1.39 beta 9) - and if you can be bothered to implement it, the best way to appreciate that is to know how to use it... so could you explain how to benefit from using CASE min TO max please ?
bugs
Posts: 142
Joined: Mon Feb 08, 2021 10:10 pm
Location: Scotland
Has thanked: 44 times
Been thanked: 50 times

Re: CASE min TO max

Post by bugs »

I requested this (back in December 2019) for this sort of use:-

Select case temperature
case 0 to 10 : tempcolour=blue
case 11 to 19: tempcolour=yellow
etc...
End select
User avatar
Electroguard
Posts: 836
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 268 times
Been thanked: 317 times

Re: CASE min TO max

Post by Electroguard »

Ah ok, so is used for groups of numbers, therefore presumably min and max need to be numeric.
User avatar
PeterN
Posts: 366
Joined: Mon Feb 08, 2021 7:56 pm
Location: Krefeld, Germany
Has thanked: 171 times
Been thanked: 203 times
Contact:

Re: CASE min TO max

Post by PeterN »

I was happy to be able to use that in my CO2-Traffic-Light code:

Code: [Local Link Removed for Guests]

'######################################################################
SET_CO2_TRAFFIC_LIGHT:

SELECT CASE eCO2
    
  CASE 300 to 500 :    'GREEN range
    PIN(LED_GREEN)  = 1 - PIN(LED_GREEN)
    PIN(LED_RED)    = 0
    PIN(LED_YELLOW) = 0
    
  CASE 501 to 700  :  'YELLOW range
    PIN(LED_YELLOW)  = 1 - PIN(LED_YELLOW)
    PIN(LED_RED)    = 0
    PIN(LED_GREEN) = 0

  CASE 701 to 9999 : 'RED range
    PIN(LED_RED)  = 0
    pause 200
    PIN(LED_RED)  = 1 - PIN(LED_RED)
    PIN(LED_GREEN)  = 0
    PIN(LED_YELLOW) = 0

  CASE ELSE:
    PIN(LED_RED)    = 1
    PIN(LED_YELLOW) = 1
    PIN(LED_GREEN)  = 1
END SELECT
return

'######################################################################
User avatar
Electroguard
Posts: 836
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 268 times
Been thanked: 317 times

Re: CASE min TO max

Post by Electroguard »

Thanks Peter, that it a clear example of usage.
User avatar
cicciocb
Site Admin
Posts: 1899
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 407 times
Been thanked: 1269 times
Contact:

Re: CASE min TO max

Post by cicciocb »

Just for info, there is a little example in the documentation
[Local Link Removed for Guests]

Code: [Local Link Removed for Guests]

CASE 7 TO 10 : PRINT "case 7 to 10"
Post Reply