hi all
How can I check if number is between to numbers using select case
for example to know if it's between 0-5 or 5-10 or 10-15
please help
thanks
Printable View
hi all
How can I check if number is between to numbers using select case
for example to know if it's between 0-5 or 5-10 or 10-15
please help
thanks
orvb.net Code:
Select Case myNumber Case 0 to 5 Case 6 to 10 Case 11 to 15 Case Else End SelectThe first one will work for whole numbers only. The second will work for floating-point numbers too.vb.net Code:
Select Case myNumber Case Is <= 5 Case Is <= 10 Case Is <= 15 Case Else End Select
I have tried it but I typed it wrong
like this
so it didn't work:confused:Code:select case mynumber
case is 0 to 5
but the one you typed worked:)
thank you for helping
You only use 'Is' when the Case expression starts with an operator rather than a value.
ok thanks
jmcilhinney Can you please elaborate as to why it behaves like this :confused:Quote:
The first one will work for whole numbers only. The second will work for floating-point numbers too.
I'm glad you asked because it made me realise that it's actually not true. They'll both work for floating point values.Quote:
Originally Posted by aashish_9601
vb.net Code:
Dim number as Integer = 7 If number > 5 and number < 10 Then ' The number is between 5-10 End If
Thats i a method too i guess..
What link wrote was what i was thinking.. but then i saw that you asked for it in the select case format.
Further to this, the range will work for floating point numbers within the range but it won't catch number between 5 and 6 or numbers between 10 and 11, so it actually isn't suitable for most scenarios where the number may not be whole.Quote:
Originally Posted by jmcilhinney