Select Case Range

P

Philosophaie

How do you use Select Case if you have a range of numbers like 0<e<1

Not 0<=e<=1 that would be Case 0 to 1.

Here is an example:
Select Case e
Case 0
'for case 0
Case 0<e<1 'this does not work
'for case 0<e<1
Case 1
'for case 1
Case Is <1
'for all cases above 1
end select
 
B

Bob Phillips

Maybe

Select Case True
Case e = 0
'for case 0
Case 0 < e And e < 1
'for case 0<e<1
Case e = 1
'for case 1
Case e < 1
'for all cases above 1
End Select
 
J

Joel

The case statement arre execute in order and stops when a match is found.
You can use the IS format

Select Case e
Case 0
'for case 0
Case 1
'for case 1
Case is < 1
'for case 0<e<1
 
D

Dana DeLouis

Case 0<e<1 'this does not work

Hi. The advantage of Select Case is to avoid additional calculations
inside (ie 0 < e < 1). Here's one way...

Sub Demo()
Dim n
n = 0.00001
Select Case n
Case 0
Debug.Print "0"
Case 1
Debug.Print "1"
Case 0 To 1
Debug.Print "0-1"
Case Else
Debug.Print "Outside Range"
End Select
End Sub

= = = = =
HTH
Dana DeLouis
 
P

Philosophaie

I need a "Case" that will activate when there are values such as 0.1, 0.4,
and 0.7 and not 0 or 1. How do I find that "Case"?
 
D

Dana DeLouis

Just another idea.

Sub Demo()
Dim n
n = 0.00001
Select Case n
Case Is <= 0: 'Do nothing
Case Is >= 1: 'Do nothing
Case 0 To 1
Debug.Print "between 0 & 1"
End Select
End Sub

= = = = =
HTH
Dana DeLouis
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top