QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: Cobalt on February 07, 2022, 04:52:48 pm

Title: Possible issue with Select Case
Post by: Cobalt on February 07, 2022, 04:52:48 pm
Ran across this today, could some of you other guys test and confirm the issue?

You should get a beep, if not then there seems to be a problem with CASE # TO #

Found in current stable version, tested in latest DB(well a week old or so) same issue for me in both.

And YES the TO keyword is allowed and used in this manner. (see image)

Code: QB64: [Select]
  1. x%% = 15
  2.  CASE 16 TO 11 'full smoke
  3.   '    _PUTIMAGE (Objects(i%%).X, Objects(i%%).Y)-STEP(15, 15), Layer(7), Layer(10), (239 + 17 * 0, 1)-STEP(15, 15)
  4.   BEEP
  5.  CASE 10 TO 5 '2\3 smoke
  6.   '    _PUTIMAGE (Objects(i%%).X, Objects(i%%).Y)-STEP(15, 15), Layer(7), Layer(10), (239 + 17 * 1, 1)-STEP(15, 15)
  7.  CASE 4 TO 1 '1\3 smoke
  8.   '    _PUTIMAGE (Objects(i%%).X, Objects(i%%).Y)-STEP(15, 15), Layer(7), Layer(10), (239 + 17 * 2, 1)-STEP(15, 15)
  9.  CASE 0 'display object
  10.   Result%% = TRUE
  11.  

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Possible issue with Select Case
Post by: SMcNeill on February 07, 2022, 05:15:09 pm
I honestly don't think it works in such a manner.  I think the range has to be lowest to highest, for it to work.

CASE 11 TO 16   rather than 16 TO 11. 

Try reversing those limits and see if it fixes the issue.
Title: Re: Possible issue with Select Case
Post by: RhoSigma on February 07, 2022, 05:40:04 pm
Yes, as Steve suggested, ranges must be given from low TO high value, however if you insist on the reverse order, then (at least for a small amount of values) a value list could be used instead of a range.
Code: QB64: [Select]
  1. x%% = 15
  2.     CASE 16, 15, 14, 13, 12, 11 'full smoke
  3.         '    _PUTIMAGE (Objects(i%%).X, Objects(i%%).Y)-STEP(15, 15), Layer(7), Layer(10), (239 + 17 * 0, 1)-STEP(15, 15)
  4.         BEEP
  5.     CASE 10, 9, 8, 7, 6, 5 '2\3 smoke
  6.         '    _PUTIMAGE (Objects(i%%).X, Objects(i%%).Y)-STEP(15, 15), Layer(7), Layer(10), (239 + 17 * 1, 1)-STEP(15, 15)
  7.     CASE 4, 3, 2, 1 '1\3 smoke
  8.         '    _PUTIMAGE (Objects(i%%).X, Objects(i%%).Y)-STEP(15, 15), Layer(7), Layer(10), (239 + 17 * 2, 1)-STEP(15, 15)
  9.     CASE 0 'display object
  10.         Result%% = TRUE
  11.  
  12.  
Title: Re: Possible issue with Select Case
Post by: Cobalt on February 07, 2022, 05:41:27 pm
I honestly don't think it works in such a manner.  I think the range has to be lowest to highest, for it to work.

CASE 11 TO 16   rather than 16 TO 11. 

Try reversing those limits and see if it fixes the issue.

Looks like your right, though why it cares?
perhaps I have gotten to used to be able to go high to low in things like LINE and _PUTIMAGE?
and it doesn't care if I CASE 16,15,14,13,12,11.
but what ever, found why there was an issue and resolved,
Thanks Steve.
Title: Re: Possible issue with Select Case
Post by: tomxp411 on February 07, 2022, 09:38:00 pm
Looks like your right, though why it cares?
perhaps I have gotten to used to be able to go high to low in things like LINE and _PUTIMAGE?
and it doesn't care if I CASE 16,15,14,13,12,11.
but what ever, found why there was an issue and resolved,
Thanks Steve.

Think about how the TO operator works.  CASE X TO Y is shorthand for
IF Value >= X AND Value <= Y THEN ...

So if you plug your numbers into the test, you get:
IF 15 >= 16 AND 15 <= 11 THEN
What is the result of this test?

The reason it works with a list (16,15,14, etc) is that the value is compared separately against each item in the list. Expressed as an IF, that's:
IF 15 = 16 OR 15 = 15 OR 15 = 14 ...

Does that make sense?
Title: Re: Possible issue with Select Case
Post by: FellippeHeitor on February 08, 2022, 08:36:13 am
Yeah, CASE lower TO higher. I keep QB4.5 in DosBOX at hand for checks like this, I recommend you do too.
Title: Re: Possible issue with Select Case
Post by: Qwerkey on February 08, 2022, 01:44:14 pm
Ah, methinks that @Cobalt must have been on some funny substance.  Everything high to low???
Title: Re: Possible issue with Select Case
Post by: bplus on February 08, 2022, 02:45:20 pm
Ah, methinks that @Cobalt must have been on some funny substance.  Everything high to low???

No he's just from O-hi-(l)o  ;-))