# Find if a number is part of a range

Hi there,
I have a little bit of an issue. I need to find out if a number is part of a giving range.
I have the following code:
``````Dim dt as new datatable
Dim dtrow as datarow

For each dtrow in dt.rows then
Dim str as string = dtrow.items("unit").tostring()
Dim range as string = dtrow.items("range").tostring()
'Some how in here I need create a function or sub that will tell me if the str is in my range or not
Next
``````
The datatable has units like this
5.000
6.00000
1.0000
23000.00
And ranges are like this:
1
2 to 5
6 to 20
21 to 50
50 >
For the bigger numbers those are dollars amounts and behave the same way.
How can I do this?
Thanks
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Business Systems Analyst , ex-Senior Application EngineerCommented:
you can try create a function accordingly for comparison.

``````Function findRange(v As Double) As String
Select Case v
Case Is > 50
Return "50 >"
Case Is >= 21
Return "21 to 50"
Case Is >=6
Return "6 to 20"
Case Is >=2
Return "2 to 5"
Case Is =1
Return "1"
Case Else
Return "< 1"
End Select
End Function
``````

then:

myRange = findRange(Convert.ToDouble(dtrow.items("range").tostring()))

Experts Exchange Solution brought to you by