그래서 축구 팀 점수에 대한 통계를 표시하려고합니다. 이 작업이 실행될 때 배열은 이미 채워져 있고 그렇지 않은 것은 아닙니다. 이 양식이 열리면 최대, 최소 및 평균 점수를 표시하고 싶습니다. 최대 및 최소 점수를 얻기 위해 선수 이름과 점수를 받고 싶습니다. 예를 들어 :목록 상자에 표시되지 않습니다 VB
Maximum: John scored 9
Minimum: Joe scored 2
같이, 나는 점수의 이름과 intScores (I)에 대한 strPlayers (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
다른 접근 방식을 시도했기 때문에 최대 값이 문자열을 반환하고 최소 및 평균값을 반환하는 이유는 작동하지 않았기 때문입니다. :/
로드 이벤트 양식에서 최대 값은 얼마입니까? – DevelopmentIsMyPassion
아무 것도 표시하지 않기 때문에 단서가 없습니다. – user1368970
나는 함수가 정확한 최대 값과 최소값을 리턴한다고 확신한다. 배열의 관점에서 표시하는 방법을 모른다. – user1368970