最高-最低价值排序文本框

时间:2019-09-15 10:22:10

标签: vb.net

Click for Image.

我想按以下顺序对这些值进行排序:最高到最低:

我有一个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

我还有另一个文本框:TxtDrawR1.Text

1
1
1
37
1
23
1
37

TextBox的创建过程如下:

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

第一个文本框中的每个值在第二个文本框中具有一个值。

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

因此,我想像这样的模型或类似的东西显示升序和降序(这些值从最低到最高):

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

从开始的行到结束的行基本上取最大值。

我不知道如何使其完全正常工作,根本不工作。

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

1 个答案:

答案 0 :(得分:1)

也许在未来的将来我也会需要它,所以我放在这里,我不知道这是否会如期实现:

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