Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Case Statement Or Syntax

Status
Not open for further replies.

Eytch

Programmer
Jan 29, 2003
60
US
Select Case MyValue


Case >= 0.5 0r < 5

Could someone tell me why my Or statement doesn't work?

Thanks,
Eytch
 
>Any valid expression ... is - because it is valid - ahem....TRUE
>123 is valid, and therefore True

Interestingly (or perhaps not) it's actually the inverse

There are two contributory factors

Firstly, the way VB actuall deals with True and False are that

a) False = 0
b) True = not False (note that isn't a boolean Not)

and secondly the condition of an If statement must be a boolean or be convertible to a boolean.

The conversion of an expression to a boolean takes place something like this (assuming that it is not already a boolean)

Is the result of evaluating the expression numeric?
If so, is it 0? Yes, then it is False, else it is True

123 in

If 123 ...

is True not because it is 'valid', but because it doesn't evaluate to 0 and therefore isn't False ...



 
I want to express the "Case" where MyValue is greater than or equal to 0.5 or less than 5.

Why wouldn't this work?

Select Case MyValue

Case 0.5 >= MyValue < 5

Thanks to All,
Eytch
 
From Eytch,

I am trying to establish several "Cases" here where MyValue falls within certain ranges of values. That is why I thought using select case statements would be appropriate.

Thanks Again.
 
Did you try PHV's suggestion made on 7 Jul 09 21:10?

Code:
Case 0.5 To 5
Works fine for me.

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
Eytch,
I want to express the "Case" where MyValue is greater than or equal to 0.5 or less than 5.
According to the above logic all numbers satisfy the above condition, as at least one condition is always true.
The next statement Case 0.5 >= MyValue < 5 indicates that you rather need to pick a value between, in this case 'and' is necessary (PHV's condition works fine except MyValue=5):
[tt]Case MyValue>=0.5 And MyValue<5[/tt]





combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top