11-07-2022, 09:09 PM
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.
I just can't do it. I even got a compiler error with it.
Select Case mistake
|
11-07-2022, 09:09 PM
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. (11-07-2022, 09:09 PM)Kernelpanic Wrote: A question about Select Case. The query should be: Case Is > 5500 but less than 7000Cannot have multiple conditions in "CASE IS". Code: (Select All) select case num If you need to do something else for "num >= 7000" then you must create another case for it above the one displayed. (11-07-2022, 09:09 PM)Kernelpanic Wrote: A question about Select Case. The query should be: Case Is > 5500 but less than 7000 Code: (Select All) Select Case num OR, another way to go about this type thing: Code: (Select All) For num = 1 To 100 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 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.
This looks like a job for SELECT CASES Which we don't have.
From my other thread: https://qb64phoenix.com/forum/showthread...LECT+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 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!
11-07-2022, 09:45 PM
(11-07-2022, 09:41 PM)Pete Wrote: This looks like a job for SELECT CASES Which we don't have. 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. What we need is an AND IS statement. CASE IS > 50, AND IS < 70
11-07-2022, 09:52 PM
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
11-07-2022, 10:14 PM
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.
11-07-2022, 10:20 PM
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
11-07-2022, 10:21 PM
(This post was last modified: 11-07-2022, 10:22 PM by Kernelpanic.)
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 Until this case it works: |
« Next Oldest | Next Newest »
|