Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort Values of 3 labels 1

Status
Not open for further replies.

Biocide

Programmer
Joined
Oct 12, 2005
Messages
12
Location
SE
Hello everybody!

I have 3 labels with 3 different values, Lets say:
Labelone.text = 23.1234
Labeltwo.text = 22.1212
Labeltree.text = 24.1234
Now i Want to check that no one is more than +- 0.2000 From another.
How?
Do i add them all in to a table and sort them?
In that case how do i do that?

As you can se im new to VB but thats not all, im also from Sweden ;)

Thanks in advance
 
An array list may be of some use:

Code:
    'Your values that I've transferred to variables to save me from having to create the labels
    'Labelone.text = 23.1234
    'Labeltwo.text = 22.1212
    'Labeltree.text = 24.1234

    Dim LabelOne As String = "23.1234"
    Dim LabelTwo As String = "22.1212"
    Dim LabelThree As String = "24.1234"

    Dim arr As New ArrayList
    arr.Add(Convert.ToDecimal(LabelOne))
    arr.Add(Convert.ToDecimal(LabelTwo))
    arr.Add(Convert.ToDecimal(LabelThree))
    For a As Integer = 0 To arr.Count - 1
      MessageBox.Show(arr(a).ToString)
    Next
    arr.Sort()
    For a As Integer = 0 To arr.Count - 1
      MessageBox.Show(arr(a).ToString)
    Next
    arr = Nothing

Hope this helps.

[vampire][bat]
 
Something like that?

Dim dblLabels(3) As Double
Dim dblDelta As Double
Dim blnOK As Boolean

dblDelta = 0.2

Label1.Text = "23.1234"
Label2.Text = "22.1212"
Label3.Text = "24.1234"


dblLabels(0) = CType(Label1.Text, Double)
dblLabels(1) = CType(Label2.Text, Double)
dblLabels(2) = CType(Label3.Text, Double)

Array.Sort(dblLabels)

blnOK = Math.Abs(dblLabels(dblLabels.GetUpperBound(0)) - dblLabels(dblLabels.GetLowerBound(0) + 1)) < dblDelta

vladk
 
I thought I'd leave Biocide to do the comparison him/herself, with the sorting being the more "difficult" problem






[vampire][bat]
 
But it is too cold in Sweden now...
 
Thanks for all replies

Vladk I would realy apreciate if you comented youre exampel, if you have time.

And yes its damn cold in sweden, im dreaming of Florida.

If
Sweden <= Cold Then
Go to Florida
end if
 
Biocide,

I introduced the Double array to store the values derived from your label captions. We need numeric equivalents of the captions since we want to treat them like numbers (compare them with each other in the field of the Double numbers). The "field" here is the numbers of type Double and regularly defined basic arithmetic operations applied to them.

Then, I sort this array with the standard VB6 method.
After the sorting, it is sufficient to look at the absolute value of the difference between the maximum and minimum values in that sorted array. The first element will be the minimum, the last - the maximum. The logical (Boolean) variable blnOK will be True if the absolute value is less than your delta (0.2). Othervise, it will be False.

vladk


 
Biocide

It is my pleasure.

earthandfire provided essentially the same code. He just did not add the final thing assuming it would be easy.

vladk
 
Yes off course.
I didn’t mean to be rude.
Thanks both off you.
I must say i admire all on this forum that give solutions to all complicated questions, but most of all i admire those that give solutions to all newbie questions like mine in this topic.
Keep up the good work!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top