|
-
Aug 7th, 2008, 08:20 AM
#1
Thread Starter
Lively Member
[RESOLVED] [2008] How to check if number between 2 numbers
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
-
Aug 7th, 2008, 08:24 AM
#2
Re: [2008] How to check if number between 2 numbers
vb.net Code:
Select Case myNumber Case 0 to 5 Case 6 to 10 Case 11 to 15 Case Else End Select
or
vb.net Code:
Select Case myNumber Case Is <= 5 Case Is <= 10 Case Is <= 15 Case Else End Select
The first one will work for whole numbers only. The second will work for floating-point numbers too.
-
Aug 7th, 2008, 08:33 AM
#3
Thread Starter
Lively Member
-
Aug 7th, 2008, 08:35 AM
#4
Re: [2008] How to check if number between 2 numbers
You only use 'Is' when the Case expression starts with an operator rather than a value.
-
Aug 7th, 2008, 09:20 AM
#5
Thread Starter
Lively Member
Re: [2008] How to check if number between 2 numbers
-
Aug 7th, 2008, 11:23 AM
#6
Frenzied Member
Re: [2008] How to check if number between 2 numbers
The first one will work for whole numbers only. The second will work for floating-point numbers too.
jmcilhinney Can you please elaborate as to why it behaves like this
-
Aug 7th, 2008, 05:06 PM
#7
Re: [2008] How to check if number between 2 numbers
 Originally Posted by aashish_9601
jmcilhinney Can you please elaborate as to why it behaves like this 
I'm glad you asked because it made me realise that it's actually not true. They'll both work for floating point values.
-
Aug 7th, 2008, 06:11 PM
#8
Addicted Member
Re: [2008] How to check if number between 2 numbers
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..
-
Aug 7th, 2008, 08:53 PM
#9
Frenzied Member
Re: [2008] How to check if number between 2 numbers
What link wrote was what i was thinking.. but then i saw that you asked for it in the select case format.
-
Aug 7th, 2008, 09:01 PM
#10
Re: [2008] How to check if number between 2 numbers
 Originally Posted by jmcilhinney
I'm glad you asked because it made me realise that it's actually not true. They'll both work for floating point values.
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|