Select Case

D

David

Hello Group,

I have a select case that is not working as I expected, Delta1ToSP =
-3.38629648094637E-02 or -.0338:

Select Case Delta1ToSP
Case -0.02 To -0.05 ' This is where I expected the stop
Stop
Case -0.050001 To -0.1
Stop
Case -0.10001 To -1
Stop
Case 0.02 To 0.05
Stop
Case 0.050001 To 0.1
Stop
Case 0.10001 To 1
Stop
Case Else
Stop
End Select

What am I missing?

Thanks,
 
R

Rick Rothstein

You must put the smaller value on the left of the "To" keyword and the
larger value on the right...

Select Case Delta1ToSP
Case -0.05 To -0.02 ' This is where I expected the stop
Stop
Case -0.050001 To -0.1
Stop
Case -1 To -0.10001
Stop
Case 0.02 To 0.05
Stop
Case 0.050001 To 0.1
Stop
Case 0.10001 To 1
Stop
Case Else
Stop
End Select
 
B

Bernard Liengme

The statement: Case -0.02 To -0.05
needs to be coded as: Case -0.05 To -0.02
since -0.05 is smaller than -0.2
Don't be too hard on yourself - it is Sunday!
best wishes
 
J

JLatham

Reverse the arguments. The negative number has twisted your head (as they
often do mine) and the Case ...To... needs small magnitude first: -.02 is
LARGER in magnitude than -0.05.

Case -0.05 To -0.02
will catch the value.
 
D

David

Thank you all. When I read through help, I don't think this was mentioned.

"Don't be too hard on yourself - it is Sunday!" Space, the final frontier,
lol.
 
D

Dave Peterson

I wouldn't use both end points.

I'd just check to see what it was less than (or less than or equal to):

Select Case Delta1ToSP
Case is <= -0.10 'that last 0 will disappear, but I kept it here!
Stop
Case is <= -0.05
Stop
Case is <= -0.02
Stop
Case is <= 0.05
Stop
Case is <= 0.10
Stop
Case is <= 1
Stop
Case Else
Stop
End select

The first case that matches is the one that is used.

And I don't have to worry about what happens at -0.0500000001
 
R

Rick Rothstein

It's mentioned in the Description for "expressionlist-n" (4th sentence) in
the table with the Part/Description heading.
 

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