所以,我試圖顯示足球隊得分的統計數據。 在執行該操作時,數組已經被填充,而不是。 當這個表單打開時,我希望它顯示最大值,最小值和平均值...... 我希望它能得到最大和最小值的球員名字和得分。例如:不會顯示在列表框中VB
Maximum: John scored 9
Minimum: Joe scored 2
一樣,我會得到在strPlayers(i)因在得分名稱和intScores(i)的值。 我很確定我有正確的功能,但無論什麼原因,我無法在加載表單時顯示列表框中的任何內容!
Public Class frmDisplayStatistics
Function FindMaximum() As String
Dim max As Integer
Dim i As Integer = 0
ReDim intScores(intNumberOfPlayers)
max = CInt(intScores(0))
For i = 0 To intNumberOfPlayers
If max < intScores(i) Then
max = CInt(intScores(i))
End If
Next
max = strPlayers(i) & " scored maximum points of " & intScores(i)
Return max
End Function
Function FindMinimum() As Integer
Dim min As Integer
Dim i As Integer = 0
ReDim intScores(intNumberOfPlayers)
min = CInt(intScores(0))
For i = 0 To intNumberOfPlayers
If min > intScores(i) Then
min = CInt(intScores(i))
End If
Next
Return min
End Function
Function FindAverage() As Double
Dim average As Double
Dim i As Integer = 0
average = total/intNumberOfPlayers
Return average
End Function
Private Sub frmDisplayStatistics_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim max As String
max = FindMaximum()
lstStatistics.Items.Add(max)
lstStatistics.Items.Add("Minimum: " & FindMinimum())
lstStatistics.Items.Add("Average: " & FindAverage())
End Sub
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
Me.Close()
End Sub
End Class
最大原因返回一個字符串,最小和平均收益的一些是因爲我嘗試了不同的方法,也沒有工作。 :/
在表單加載事件中,變量max的值是多少? – DevelopmentIsMyPassion 2013-05-04 22:10:02
我不知道,因爲它不顯示任何東西。 – user1368970 2013-05-04 22:18:59
我敢肯定,函數返回正確的最大值和最小值,我只是不知道如何顯示它們的陣列方面! – user1368970 2013-05-04 22:19:38