user11251258
user11251258

Reputation:

Highest - Lowest value sort Textboxes

Click for Image.

I would like to order these values ascending and descending: the highest to the lowest:

I have a TextBox TxtNumberListScan =

1 3 5 7
1 3 5 8
1 3 5 9
1 3 6 7
1 3 6 8
1 3 6 9
1 3 7 8
1 3 7 9

I have another TextBox: TxtDrawR1.Text

1
1
1
37
1
23
1
37

This TextBox was created as follows:

TxtDrawR1.Text &= Environment.NewLine & lastDraw1
TxtDrawR2.Text &= Environment.NewLine & lastDraw2
TxtDrawR3.Text &= Environment.NewLine & lastDraw3
While ListTxtDrawR1.Items.Count > 0
ListTxtDrawR1.Items.RemoveAt(ListTxtDrawR1.Items.Count - 1)
End While
For i As Integer = 0 To TxtDrawR1.Lines.Count - 1
ListTxtDrawR1.Items.Add(TxtDrawR1.Lines(i))
Next
While ListTxtDrawR2.Items.Count > 0
ListTxtDrawR2.Items.RemoveAt(ListTxtDrawR2.Items.Count - 1)
End While
For i As Integer = 0 To TxtDrawR2.Lines.Count - 1
ListTxtDrawR2.Items.Add(TxtDrawR2.Lines(i))
Next
While ListTxtDrawR3.Items.Count > 0
ListTxtDrawR3.Items.RemoveAt(ListTxtDrawR3.Items.Count - 1)
End While

Each value in the first Textbox has a value in the 2nd Textbox.

1 3 5 7 = 1 
1 3 5 8 = 1
1 3 5 9 = 1
1 3 6 7 = 37
1 3 6 8 = 1
1 3 6 9 = 23
1 3 7 8 = 1
1 3 7 9 = 37

so I want to display ascending and descending (from lowest to highest these values) as follows such a model or something similar:

1 3 6 7 = First Line - because it is the highest value - 37 - starting from the first.
1 3 7 9 = 2st Line - because again it is the highest value in the first Textbox. - value - 37
1 3 6 9 = 3st Line - value - 23 
1 3 5 7 = 4st Line - value 1
1 3 5 8 - 5st Line - value 1
1 3 5 9 - 6st Line - value 1
1 3 6 8 - 7st Line - value 1
1 3 7 8 - 8st Line - value 1

Basically the highest value is taken from the beginning Line to the end Lines.

I don't know how to make it work exactly as it should, it doesn't work at all.

Dim Top10HighestValues = myList.Select(Function(line)
                                          Dim res = 0
                                          Integer.TryParse(line, res)
                                          Return res
                                        End Function).OrderByDescending(Function(x) x).Take(10)
  Dim dictionary As New Dictionary(Of String, Integer)
  For Each i In Top10HighestValues 
       Dim idx = myList.IndexOf(i) + removedEmptyLinesCount
       dictionary.Add(i, idx)
  Next
 For Each d In Dictionary
        TextBox2.AppendText(d.Key & vbCrLf)
        TextBox2.AppendText(d.Value & vbCrLf)
 Next

Upvotes: 0

Views: 83

Answers (1)

user11982798
user11982798

Reputation: 1908

May be I will need this too in next future, so I put here, I can't know whether this will run as hope or not:

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    Dim ListScan = TxtNumberListScan.Lines.ToList.Select(Function(o, i) New With {.scan = o, .Index = i})
    Dim DrawR1 = TxtDrawR1.Lines.ToList.Select(Function(o, i) New With {.draw = o, .Index = i})
    Dim list3 = From a In ListScan From b In DrawR1 Where a.Index = b.Index Select LstScan = a.scan, DrwR1 = b.draw Order By DrwR1 Descending
End Sub

Upvotes: 2

Related Questions