0
我是初學者,需要學校項目的幫助。我試圖讓分數顯示從最高到最低和平均分數。我怎樣才能做到這一點?我目前的代碼是:VB上的算術測驗
Dim filename As String
Dim numberofrecords As Short
Dim countofloop As Short
Dim one, two, three As Short
filename = "N:\Class1.dat"
FileOpen(1, filename, OpenMode.Random, , , Len(OneStudentScore))
numberofrecords = LOF(1)/Len(OneStudentScore)
countofloop = 0
Dim scores(numberofrecords) As Integer
Dim names(numberofrecords) As String
Do While (Not EOF(1))
FileGet(1, OneStudentScore)
one = OneStudentScore.score1
two = OneStudentScore.score2
three = OneStudentScore.score3
names(countofloop) = OneStudentScore.Name
If one > two Then
If one > three Then
'1st score is the biggest
scores(countofloop) = one
Else
scores(countofloop) = three
End If
Else
If two > three Then
scores(countofloop) = two
Else
scores(countofloop) = three
End If
End If
countofloop = countofloop + 1
Loop
'sort array into score order
Array.Sort(scores, names)
'this allows the arrays to be in descending order - highest first
Array.Reverse(scores)
Array.Reverse(names)
Dim displayeditem As String
lstClass1.Items.Clear()
'display the arrays in a list box
For i = 0 To countofloop
displayeditem = names(i) & " " & scores(i)
lstClass1.Items.Add(displayeditem)
FileClose()
Next
End Sub
End Class
你好。好吧,得分最高的是,當我點擊最高到最低的按鈕並且分數沒有顯示在正確的列中時,它在列表視圖中的名稱下隨機出現一個零。 – BradR