QB64 Phoenix Edition
Select Case mistake - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10)
+---- Thread: Select Case mistake (/showthread.php?tid=1070)

Pages: 1 2


Select Case mistake - Kernelpanic - 11-07-2022

A question about Select Case. The query should be: Case Is > 5500 but less than 7000

I just can't do it. I even got a compiler error with it.

[Image: Select-Case-Fehler2022-11-07.jpg]


RE: Select Case mistake - mnrvovrfc - 11-07-2022

(11-07-2022, 09:09 PM)Kernelpanic Wrote: A question about Select Case. The query should be: Case Is > 5500 but less than 7000
Cannot have multiple conditions in "CASE IS".
Code: (Select All)
select case num
    case is > 5500
        if num < 7000 then
            'do what you need to do
        end if
end select

If you need to do something else for "num >= 7000" then you must create another case for it above the one displayed.


RE: Select Case mistake - SMcNeill - 11-07-2022

(11-07-2022, 09:09 PM)Kernelpanic Wrote: A question about Select Case. The query should be: Case Is > 5500 but less than 7000

I just can't do it. I even got a compiler error with it.

[Image: Select-Case-Fehler2022-11-07.jpg]


Code: (Select All)
Select Case num
    Case 5001 To 6999
        'Do what you need to do
End Select

OR, another way to go about this type thing:

Code: (Select All)
For num = 1 To 100
    Select Case num
        Case Is >= 70 'Do nothing but elimate values > 70
        Case Is > 50 'Do what you need to do
            Print num,
    End Select
Next



RE: Select Case mistake - SMcNeill - 11-07-2022

Quote:Cannot have multiple conditions in "CASE IS".

That's not quite right.  You just won't generate the answers you're expecting, I don't imagine. 

Code: (Select All)
For num = 1 To 100
    Select Case num
        Case Is > 50, Is < 70
            'Do what you need to do
            Print num,
    End Select
Next

Multiple CASE IS statements seem to work as OR comparisons and not AND comparisons.  In this case it's basically IF num >50 OR num < 70, which is all our numbers...  

Looks like TO is the solution for numbers in a range.  Smile


RE: Select Case mistake - Pete - 11-07-2022

This looks like a job for SELECT CASES Which we don't have. Sad

From my other thread: https://qb64phoenix.com/forum/showthread.php?tid=978&highlight=SELECT+CASES

We have a split between devs on putting it into QB64 so who knows, maybe someday.

Anyway, don't get fooled by whatever the heck this is...

Code: (Select All)
a = 1600
SELECT CASE a
    CASE IS > 500, IS < 700
        PRINT "Wrong!"
END SELECT

Funny it looks like it should work, but of course it won't; but I find it curious we can divide up CASE statements with commas like this. So I don't get the logic here. This sample will print "Wrong!" when it should print nothing, as 1600 is > 500 but NOT smaller than 1600 to satisfy an a > 500 AND a < 700, BUT AGAIN, no "AND" SO THIS IS NOT WHAT THE CODE IS SET UP TO DO. So what is the comma use is set up to do? I'd have to go research that a bit to figure it out. I just thought I'd bring it up for the fun of it. I just use what mn demonstrated when I need these SELECT CASES (we don't have) situations.

Did I mention we don't have SELECT CASES?

EDIT: Nice, I see Steve addressed the comma issue. I've used the CASE TO range method as well, but apparently not recently enough for it to be on the tip of my brain. Yeah, it gets pretty pointy under that big hat I wear.

Pete

We don't have SELECT CASES, varmint!


RE: Select Case mistake - SMcNeill - 11-07-2022

(11-07-2022, 09:41 PM)Pete Wrote: This looks like a job for SELECT CASES Which we don't have. Sad

From my other thread: https://qb64phoenix.com/forum/showthread.php?tid=978&highlight=SELECT+CASES

We have a split between devs on putting it into QB64 so who knows, maybe someday.

Anyway, don't get fooled by whatever the heck this is...

Code: (Select All)
a = 1600
SELECT CASE a
    CASE IS > 500, IS < 700
        PRINT "Wrong!"
END SELECT

Funny it looks like it should work, but of course it won't; but I find it curious we can divide up CASE statements with commas like this. So I don't get the logic here. This sample will print "Wrong!" when it should print nothing, as 1600 is > 500 but NOT smaller than 1600 to satisfy an a > 500 AND a < 700, BUT AGAIN, no "AND" SO THIS IS NOT WHAT THE CODE IS SET UP TO DO. So what is the comma use is set up to do? I'd have to go research that a bit to figure it out. I just thought I'd bring it up for the fun of it. I just use what mn demonstrated when I need these SELECT CASES (we don't have) situations.

Did I mention we don't have SELECT CASES?

Pete

We don't have SELECT CASES, varmint!

AS I mentioned:  It works as an OR comparison.  Think of it as:

SELECT CASE 1, 2, 3, 5, 7, 9

^The above is for 1 OR 2 OR 3 OR 5 OR 7 OR 9....

SELECT CASE IS > 50, IS < 70 is basically IF whatever > 50 OR whatever < 70 THEN....   

It's basically bad programmer logic which is going to be true all the time, but it *is* a valid syntax.  Tongue



What we need is an AND IS statement.

CASE IS > 50, AND IS < 70


RE: Select Case mistake - Pete - 11-07-2022

Well maybe let's talk it over with Matt and Roland. Maybe we have reached something we all can agree on. The "OR" is worthless, and yet it's there. The AND could be added and would be valuable.

Pete


RE: Select Case mistake - mnrvovrfc - 11-07-2022

Wow I reached 400 posts so soon, have 4.5% of the "total" posts on this site. Need to take a vacation LOL...

I never thought about "TO" when I made my previous post, but couldn't figure out neither what the OP required in his program.


RE: Select Case mistake - Pete - 11-07-2022

Yep, you're very much the Chatty Cathy around these parts, that's for sure. Hey, is that Cathy with a "C" or Kathy with a "K" do you suppose? I sometimes wonder where all these sayings come from, but... oh crap... as if the API Princes nick name wasn't bad enough. I'll shut up now.

Cathy Pete


RE: Select Case mistake - Kernelpanic - 11-07-2022

Thank you for the hints. But unfortunately none of that works.
It's about Select Case and Select EveryCase. I wrote a small program about buying a used car to illustrate this. The program shall fall on Case Else if the purchase price is greater than 7000.00.

If greater than 5500.00, then "VW Polo . . ." are displayed, but also if it ist greater 7000.00. Yes, maybe Select Case really doesn't work so and you have to come up with something else.

Code: (Select All)
'Beispiel fuer Select Case und EveryCase - 7. Nov. 2022

Option _Explicit

Dim As Double kaufpreis

Print "Gebrauchtwagenkauf"
Print
Input "Wieviel moechten Sie ausgeben? ", kaufpreis

Print "Select Case:"
Select Case kaufpreis
  Case 4000 To 5000
    Print "Trabant, blau, frisiert - 31 KW."
  Case 5000 To 6000
    Print "Wartburg, dunkelgruen, 74.00 KM, 40 KW."
  Case Is > 5500
    Print "VW Polo, beige, 110.000 KM, 44 KW"
  Case Else
    Print "Haben wir leider nicht im Angebot!"
End Select

Print
Print "Select EveryCase:"
Select EveryCase kaufpreis
  Case 4000 To 5000
    Print "Trabant, blau, frisiert - 31 KW."
  Case 5000 To 6000
    Print "Wartburg, dunkelgruen, 74.00 KM, 40 KW."
  Case Is > 5500
    Print "VW Polo, beige, 110.000 KM, 44 KW"
  Case Else
    Print "Haben wir leider nicht im Angebot!"
End Select

End

Until this case it works:

[Image: Case-BSP2022-11-07-214855.jpg]