Select Case Fails

  • Thread starter Thread starter Bob Day
  • Start date Start date
B

Bob Day

using vs 2003 ...

This works fine
Select Case 350
Case 300 To 399
Stop
End Select

This fails with no warning
Select Case 520
Case Not 300 To 399
Stop
End Select

Why?

Bob Day
 
Bob Day said:
using vs 2003 ...

This works fine
Select Case 350
Case 300 To 399
Stop
End Select

This fails with no warning
Select Case 520
Case Not 300 To 399
Stop
End Select

Why?


"Not 300" is equal to -301. "Not" inverses all bits:
300 = 0000000100101100 => Not 300 = 1111111011010011 = -301

So, "Case Not 300 To 399" is equal to "Case -301 To 399"

Use instead:
select case 520
case 300 to 399
'empty
case else
stop
end select
 
Hi Bob

I suspect the Not is being applied to 300, thus is the same as

Select Case 520
Case (Not 300) To 399
Stop
End Select

Charles
 
I don't think the NOT will work. I've tried and haven't been able to do it.
However, you can get the result you want by testing the affirmative and just
not respoding....

Select Case 520
Case 300 to 399
Case Else
'your code here.
End Select

HTH

Bill

If you use 520, it'll ne
 
Hello,

Bob Day said:
This works fine
Select Case 350
Case 300 To 399
Stop
End Select

This fails with no warning
Select Case 520
Case Not 300 To 399
Stop
End Select

Why?

Have a look at the other replies for an explanation.

\\\
Dim i As Integer = 350
Select Case i
Case i < 300 And i > 399
Stop
End Select
///

;-)
 
Hi Herfried

You didn't have Option Strict On when you wrote that, did you?

How about

Dim i As Integer = 520

Select Case i
Case Is < 300, Is > 399
Stop

End Select

;-)

Charles
 
Hi Herfried,

True words are spoken:

Select Case i
Case i < 300 And i > 399

Equals

Select Case i
Case False

Oops! :-)

Regards,
Fergus
 
Hello,

Charles Law said:
Hi Herfried

You didn't have Option Strict On when you wrote that, did you?

Sorry, I was in god mode. I wanted to write:

\\\
Dim i As Integer = 350
Select Case True
Case i < 300 And i > 399
Stop
End Select
///
How about

Dim i As Integer = 520

Select Case i
Case Is < 300, Is > 399
Stop

End Select

;-)
 
Hello,

Fergus Cooney said:
True words are spoken:

Select Case i
Case i < 300 And i > 399

Equals

Select Case i
Case False

Oops! :-)

Yep... I know, a typo -- see my reply to Charles.
 
Back
Top