user1368970
user1368970

Reputation: 555

Will not display in list box VB

So, I'm trying to display the statistics for a soccer teams points scored. At the time this is being executed, the arrays have been already filled and what not. When this form opens, I'd like it to display the maximum, minimum, and average scores.... I want it to get the players name and score for max and min. For example:

    Maximum: John scored 9

    Minimum: Joe scored 2

Like, i'd be getting the value at strPlayers(i) for the name and intScores(i) for score. I'm pretty sure I had the functions correct, but, for whatever reason, I can not get it to display anything in the list box upon loading the form!

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

The reason maximum returns a string and minimum and average return a number is because I was trying a different approach, that also did not work. :/

Upvotes: 0

Views: 1759

Answers (1)

DevelopmentIsMyPassion
DevelopmentIsMyPassion

Reputation: 3591

Assuming you are getting array in the variable max in the form load event. Then you should loop the array. Like below

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

Also you need to declare variable max as array. Hope you got my point

Upvotes: 1

Related Questions