Nikolay,
You can use a Select Case if you have fixed ranges, otherwise I would
probably use an IntegerRange class.
http://www.martinfowler.com/ap2/range.html
Something like:
Dim range1 As New IntegerRange(1, 500)
Dim range2 As New IntegerRange(501, 1000)
Dim range3 As New IntegerRange(1001, 1500)
Dim range4 As New IntegerRange(1501, 2000)
Dim value As Integer = 100
If range1.Contains(value) Then
' do stuff for 1-500
ElseIf range2.Contains(value) Then
' do stuff for 501-1000
ElseIf range3.Contains(value) Then
' do stuff for 1001-1500
ElseIf range4.Contains(value) Then
' do stuff for 1501-2000
End If
Where range1, range2, range3, range4 are individually part of another
abstraction (class) that could work polymophically based on an overridable
"Action" method, I would then put this other abstraction into a collection
and simply iterate the collection looking for a specific range & call the
"Action" method of the object that was found... Note the "Action" method
could simply be a Delegate, then this second abstraction would simply need
to be an IntegerRange & Delegate pair.
Public Structure IntegerRange
Private ReadOnly m_start As Integer
Private ReadOnly m_finish As Integer
Public Sub New(ByVal start As Integer, ByVal finish As Integer)
If start > finish Then Throw New ArgumentException("Start cannot be
after finish")
m_start = start
m_finish = finish
End Sub
Public ReadOnly Property Start() As Integer
Get
Return m_start
End Get
End Property
Public ReadOnly Property Finish() As Integer
Get
Return m_finish
End Get
End Property
Public ReadOnly Property Duration() As Integer
Get
Return m_finish - m_start
End Get
End Property
Public Function Contains(ByVal value As Integer) As Boolean
Return (m_start <= value AndAlso value <= m_finish)
End Function
End Structure
Hope this helps
Jay
"Nikolay Petrov" <jo******@mail.bg> wrote in message
news:uP**************@TK2MSFTNGP12.phx.gbl...
I junt can't figures this out. Can somebody help.
I have list of numbers
00000001
00000002
00000003
00000004
00000005
00000006
00000007
00000008
and so on
I want to define some range like
1-500
501-1000
1001-1500
1501-2000
...
What I need is how to find which number in which range belongs.
Can someone help?
TIA