0

所以,我试图显示足球队得分的统计数据。在执行此操作时,数组已经被填充,什么还没有。当此表单打开时,我希望它显示最高、最低和平均分数……我希望它能够获取球员姓名以及最高和最低分数。例如:

    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

最大值返回一个字符串而最小值和平均值返回一个数字的原因是因为我尝试了一种不同的方法,但也没有用。:/

4

1 回答 1

1

假设您在表单加载事件中的变量 max 中获取数组。然后你应该循环数组。像下面

for i = 0 to max.count -1
     listbox.item.add(i)
 next

您还需要将变量 max 声明为数组。希望你明白我的意思

于 2013-05-04T22:39:02.687 回答