# Is there a vb.net function that allows you to test for the lowest, intermediate and highest of 3 numbers?

I would like to test the order of 3 given numbers to make sure that they are in the order of low, intermediate and high using vb.net
###### 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.

Commented:
No. There isn't such a function of of the box. You can easily write your own.

Example 1
Loop through the list, comparing each item with the next. If you lost is suppsed to be sorted in ascending order, then the next item should always be bigger than the previous item

Example 2
Create a New List(Of Long)
Add the numbers to this list
Sort this list

Loop through the list with the numbers in their original order, and compare the item at each index with the new, sorted list. If you find any mismatch, then the numbers are not sorted
DeveloperCommented:
You can accomplish this with LINQ fairly easily:
``````Module Module1
ReadOnly values As Integer() = New Integer() {6, 9, 23, 67, 43, 64, 29, 82, 7, 99, 2}
Sub Main()
Dim ordered = (From i In values Order By i Select i)
Console.WriteLine("The ordered values are: [ {0} ]", String.Join(", ", Array.ConvertAll(ordered.ToArray(), Function(x) x.ToString())))
Dim lowest = ordered.Take(3)
Console.WriteLine("The lowest values are: [ {0} ]", String.Join(", ", Array.ConvertAll(lowest.ToArray(), Function(x) x.ToString())))
Dim middle = ordered.Skip(Convert.ToInt32(values.Count() \ 2) - 1).Take(3)
Console.WriteLine("The middled values are: [ {0} ]", String.Join(", ", Array.ConvertAll(middle.ToArray(), Function(x) x.ToString())))
Dim highest = ordered.Reverse().Take(3)
Console.WriteLine("The highest values are: [ {0} ]", String.Join(", ", Array.ConvertAll(highest.ToArray(), Function(x) x.ToString())))

Console.WriteLine()
End Sub
End Module
``````
Which produces the following output --saige-
DeveloperCommented:
Ofcourse if the ordering on the last set of integers matters, then you can simply reverse it again:
``````Module Module1
ReadOnly values As Integer() = New Integer() {6, 9, 23, 67, 43, 64, 29, 82, 7, 99, 2}
Sub Main()
Dim ordered = (From i In values Order By i Select i)
Console.WriteLine("The ordered values are: [ {0} ]", String.Join(", ", Array.ConvertAll(ordered.ToArray(), Function(x) x.ToString())))
Dim lowest = ordered.Take(3)
Console.WriteLine("The lowest values are: [ {0} ]", String.Join(", ", Array.ConvertAll(lowest.ToArray(), Function(x) x.ToString())))
Dim middle = ordered.Skip(Convert.ToInt32(values.Count() \ 2) - 1).Take(3)
Console.WriteLine("The middled values are: [ {0} ]", String.Join(", ", Array.ConvertAll(middle.ToArray(), Function(x) x.ToString())))
Dim highest = ordered.Reverse().Take(3).Reverse()
Console.WriteLine("The highest values are: [ {0} ]", String.Join(", ", Array.ConvertAll(highest.ToArray(), Function(x) x.ToString())))

Console.WriteLine()
End Sub
End Module
``````
Which now produces the following output --saige-
RetiredCommented:
Hi taviaf;

The following code snippet should do what you need.
``````' Test sequence, this when tested will return False
Dim listOfNumbers As New List(Of Integer) From { 1, 100, 10 }

' Test to see if the sequence is in low to high order
Dim isSameOrder = listOfNumbers.OrderBy(Function(i) i).ToList().
Zip(listOfNumbers, Function(l1, l2) l1 = l2).
All(Function(b) b = True)
``````
RetiredCommented:
Hi  taviaf;

Has the solution I posted above work for you or are you still needing help?

Thanks

Experts Exchange Solution brought to you by