我有一个问题在VB作业分配上排序结构

时间:2017-04-13 16:48:38

标签: vb.net

我正在尝试从文本文件中读取许多胜利和团队名称,然后我尝试按照降序排列的结果对结构进行排序。但是它不允许我按output.wins订购,我不知道为什么。我按照老师提供的例子。在let output.wins = output中,它表示预期.=的位置。有人可以指出我错过了什么吗?我并没有在正确的方向上寻找答案,而是我搞砸了。

Public Class frmScoccer

    Structure Team
        Dim name As String
        Dim wins As Integer
    End Structure

    Dim output() As Team 'this is going to be holder for the output data. 
    Private Sub frmScoccer_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'this is going to be doing everything that needs to be done at load time. 
        Dim grabNames() As String = IO.File.ReadAllLines("Names.txt") 'this is to pull the names from the text file. 
        Dim names() As String 'this is going to be the array that holds the names. 
        'this is going assigned the names to the array

        Dim grabWins() As String = IO.File.ReadAllLines("Wins.txt") 'this is going to be used to grab the data on wins before it is assigned to the array. 
        Dim wins(,) 'this is going to hold wins and loses.

        nameAssignment(grabNames, output)
        winAssignment(grabWins, wins)

        countIf(wins, output) 'this is going to count the number of wins per team. 

    End Sub

    Sub countIf(wins, ByRef output)
        'this is going to bring the win counter up for a team if the value is true.

        For row As Integer = 0 To (wins.getupperbound(0))
            output.name(row) = 0
            For column As Integer = 0 To (wins.getupperbound(1))
                If wins(row, column) = "true" Then
                    output.wins += 1
                End If
            Next
        Next

    End Sub

    Sub nameAssignment(grabNames, ByRef output)
        'this is goning to be a way to get the names from the input array to the useable array. 
        Dim line, data() As String
        line = grabNames()
        data = line.Split(","c)
        For Each i As String In data
            output.name(i) = data(i)
        Next
    End Sub

    Sub winAssignment(grabWins(), ByRef wins(,))
        Dim line, data() As String
        For row As Integer = 0 To (grabWins.GetUpperBound(0))
            line = grabWins(row)
            data = line.Split(","c)
            For column As Integer = 0 To (grabWins.GetUpperBound(1))
                wins(row, column) = data(column)
            Next
        Next
    End Sub

    Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click
        'this is going to display the output

        Dim query = From win In output
                    Let output.wins = output
                    Order By output Descending
                    Select win
        For Each win In query()
            dgvTeamWins.DataSource = query.Tolist
            dgvTeamWins.CurrentCell = Nothing

            dgvTeamWins.Columns("name").HeaderText = "Team"
            dgvTeamWins.Columns("wins").HeaderText = "Wins"
        Next

    End Sub

End Class

1 个答案:

答案 0 :(得分:0)

我误解了查询是如何工作的。它是通过替换

来解决的
Dim query = From win In output
                    Let output.wins = output
                    Order By output Descending

Dim query = From win In output 
Order By win.wins Descending