Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 在“我的行”文本框中显示前10个最高/较低值_Vb.net - Fatal编程技术网

Vb.net 在“我的行”文本框中显示前10个最高/较低值

Vb.net 在“我的行”文本框中显示前10个最高/较低值,vb.net,Vb.net,我想深化这段代码,并向我展示前10个最高值和10个最低值。你认为有可能按照给我的例子来做吗 Dim myList = TxtNumberListCount.Lines.ToList Dim removedEmptyLinesCount = myList.RemoveAll(Function(str) String.IsNullOrWhiteSpace(str)) Dim minValue = myList.Select(Function(line)

我想深化这段代码,并向我展示前10个最高值和10个最低值。你认为有可能按照给我的例子来做吗

  Dim myList = TxtNumberListCount.Lines.ToList
        Dim removedEmptyLinesCount = myList.RemoveAll(Function(str) String.IsNullOrWhiteSpace(str))
        Dim minValue = myList.Select(Function(line)
                                         Dim res = 0
                                         Integer.TryParse(line, res)
                                         Return res
                                     End Function).Min() ' or Max()
        Dim lineIndex = myList.IndexOf(minValue) + removedEmptyLinesCount
        TxtBoxMinValue1.Text = minValue
        TxtBoxCountMinValue1.Text = lineIndex
        Dim myList1 = TxtNumberListCount.Lines.ToList
        Dim removedEmptyLinesCount1 = myList1.RemoveAll(Function(str) String.IsNullOrWhiteSpace(str))
        Dim maxValue = myList1.Select(Function(line)
                                          Dim res = 0
                                          Integer.TryParse(line, res)
                                          Return res
                                      End Function).Max() ' or Max()
        Dim lineIndex1 = myList1.IndexOf(maxValue) + removedEmptyLinesCount
        TxtBoxMaxValue1.Text = maxValue
        TxtBoxCountMaxValue1.Text = lineIndex1
        TextBox6.Text = TxtNumberListScan.Lines(TxtBoxCountMinValue1.Text)
        TextBox7.Text = TxtNumberListScan.Lines(TxtBoxCountMaxValue1.Text)

要获得最多10个最高值,请执行以下操作:

Dim Top10HighestValues = myList.Select(Function(line)
                                          Dim res = 0
                                          Integer.TryParse(line, res)
                                          Return res
                                        End Function).OrderByDescending(Function(x) x).Take(10)
要获得最多10个最低值,您需要将OrderByDescending替换为OrderBy:

将值和索引保存到字典中:

  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

编辑以获取索引

如何计算行数?查找所有值的行。LineIndex更新了answerNot索引,以及每个值位于哪一行。上一个代码更好。您必须保留上一个代码,我看到您已将其删除。对于Top10HighestValues TextBox2.AppendTexti&vbCrLf Next中的每个I
  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