【发布时间】:2013-05-04 21:46:07
【问题描述】:
所以,我正在尝试显示足球队得分的统计数据。 在执行此操作时,数组已经被填充,什么还没有。 当此表单打开时,我希望它显示最高、最低和平均分数.... 我希望它得到球员的名字和得分的最大值和最小值。例如:
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 的值是多少?
-
我不知道,因为它不显示任何内容。
-
我很确定函数返回正确的最大值和最小值,我只是不知道如何根据数组显示它们!
-
好的,所以它返回你的数组。我认为你不能像这样添加数组。你需要循环它们
标签: arrays vb.net function vba listbox