-2
我想從文本文件中讀取一些勝利和團隊名稱,然後我嘗試通過降序排列結構。但它不會讓我通過output.wins
訂購,我不知道爲什麼。我跟着老師提供的例子。在let output.wins = output
它說,.
是=
預計。有人能指出我錯過了什麼嗎?我不是在尋找答案,只是在正確的方向上對我搞砸了什麼。我有一個問題,在VB家庭作業上排序一個結構
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
'昏暗查詢替換
=從贏在輸出順序按win.wins Descending'? – GSerg
'我不是在尋找答案...'但這就是所有關於!其問題和*答案*網站。它不適用於根據實施可能或不可能工作的建議或一般想法。 – Plutonix
@Plutonix。有道理。 – Grimmjow91