Select Case statement - General Q

ahuvas

Registered User.
Local time
Today, 05:36
Joined
Sep 11, 2005
Messages
140
If I write a select case statement for a field X i.e. 6 to 7 for example will this:

1. Select any fields X where the number is greater than or equal to 6 but less than (and not including) 7

B. Select any fields X where the number is greater than or equal to 6 but includes decimels of 7 i.e. 7.5

OR

C. Select any fields X where the number is greater than or equal to 6 but includes but literally only includes cases where the the whole number 7 appears>

I only ask because in an example in a book I am looking at says:

Case 10000 to 20000
......
Case 20001 to 30000

I would have through the word "to" means until but not including but in this case the field that equals 20000 would never be selected?
 
My guess is that it is inclusive just as the Between ... And... is inclusive.

They all probably translate into >= <=

Brian
 
Whole numbers or decimels for the second number?

THe other reason I ask is because I have a select case statement that says:

Case Is > 85
Component4Score = 0

Case 75 To 84
Component4Score = 1

Case 65 To 74
Component4Score = 2

Case Is < 65
Component4Score = 3

Case Else
Component4Score = "#Error"

End Select

I always thought if they got a score of 84.5 for example they would recieve a value of 1 but now I am not so sure.
 
Last edited:
I edited my post and crossed your second, sorry.

6 to 7 will mean just that I think 7.000000000001 would not qualify, but only testing would clarify for sure.

Brian
 
Okay just wanted to check. I think I am better using off < = > symbols so I can be sure what I am asking than on relying on to..
 
Couldn't resist a quick test, It seems that Select Case is lacking a function such as And so that one could for example

Select Case fldn
case is >=1000 And <2000
to allow for decimal places but not pull in 2000 in an attempt to cover 1999.99 say, the only way appears to use nested Selects which seems a bit over the top. Still i've never needed to do it and wont now so why should I worry. :D

Brian
 
I believe to accomplish this you'd do:
Code:
Select Case fldn
case is >=1000, is <2000
 
Nope it treats those as 2 separate conditions and therefore you would get everything.

Brian
 
Nope it treats those as 2 separate conditions and therefore you would get everything.

Brian

Good point -- sorry about that.

I'm not sure I'd use a Select Case with situations involving numbers that don't have a defined decimal tolerance.

One option that would work though is to properly order your cases to allow for such situations.
Code:
Select case fldn
case is >2000
   ' filters out all numbers > 2000 (not including 2000 itself)
case is >=1000
   ' if the number gets by the first case it has to be <= 2000
end select
 
Good point so to select everything from 1000 to 2000 but not including 2000
Case is >=2000
Case is >=1000

so by careful ordering you could achieve what was required.
Thanks for that input, now to find a use for it. :D

brian
 
So if I used my example above with component 4 etc.. my case statements wont select value if it is 84.5 - and I should use the nest case >=75 and <85 <- this way it would pick up all values of 75, 76...84 including decimals of 84.
 
Case Is >= 85
'grabs everything with a score of 85 or greater
Component4Score = 0

Case is >=75
'grabs everything from 75 to 84.9999...
Component4Score = 1

Case is >= 65
Component4Score = 2

Case Is < 65
Component4Score = 3

Case Else
Component4Score = "#Error"

End Select
 
Hey Ahuvas iI had forgotten about your original question :o, but the Golfpro has beaten par so you are ok now.

brian
 
Okay I know this is overboard but I just want to make sure I am doing it properly.

If my scoring is:

<= 15 minutes = 0
16-30 minutes = 1
31-60 minutes = 2
> 60 minutes = 3


Then the code would be:

Case Is > 60
Me.Q2PSQIRC = 3

Case Is >= 31
Me.Q2PSQIRC = 2

Case Is >= 16
Me.Q2PSQIRC = 1

Case Is <= 15
Me.Q2PSQIRC = 0

Case Else
Me.Q2PSQIRC = "#Error"

End Select

End Sub
 
Your original posts all asked about decimals, but your solution, which appears otherwise fine, ignores values between 15 and 16, I presume we are dealing in integers here.
Actually after my last post I decided that we had made mountains out of molehills by taking an isolated value, I'm sure everything is going to be simple and correct.

Brian
 
You actually made an important point about 15 and 16 - we should be dealing with whole numbers in this particular case however when I am asking participants to fill in info who the heck knows? They never follow instructions anyway.

In general though I was following the scoring code for the written questionnaire but the reality is that when people are inputing data and averages or calculations are being made there are decimals and fractions all over the place - it is better to be safe than sorry. 1 point here or there could mean the difference in participating or not.
 

Users who are viewing this thread

Back
Top Bottom