Author Topic: Possible issue with Select Case  (Read 3202 times)

0 Members and 1 Guest are viewing this topic.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Possible issue with Select Case
« 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.  

  [ You are not allowed to view this attachment ]  
Granted after becoming radioactive I only have a half-life!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Possible issue with Select Case
« Reply #1 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.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: Possible issue with Select Case
« Reply #2 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.  
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Possible issue with Select Case
« Reply #3 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.
Granted after becoming radioactive I only have a half-life!

Offline tomxp411

  • Newbie
  • Posts: 28
    • View Profile
Re: Possible issue with Select Case
« Reply #4 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?

FellippeHeitor

  • Guest
Re: Possible issue with Select Case
« Reply #5 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.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: Possible issue with Select Case
« Reply #6 on: February 08, 2022, 01:44:14 pm »
Ah, methinks that @Cobalt must have been on some funny substance.  Everything high to low???

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Possible issue with Select Case
« Reply #7 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  ;-))