I have to create a cafeteria survey application. Twenty students were asked to reate, on a scale of 1 to 10, the quality of the food in the student cafeteria, with 1 being "awful" and 10 being "excellent." Allow the user input to be entered using a ComboBox. Use an integer array to store the frequency of each rating. Display the frequencies as a bar chart in a list box.

I can get the comboBox and everthing, but it's not displaying the bar chart. Any help would be appreciated. Here is my code.

Public Class Form1

    'String array stores ratings
    Dim ratings() As String = {"1-Awful", "2", "3", "4", "5", "6", "7", "8", "9", "10-Excellent"}
    Dim studentCount As Integer 'number of student ratings entered
    Dim frequency(9) As Integer

    Private Sub CafeteriaSurvey_Load(ByVal sender As System.Object,
        ByVal e As System.EventArgs) Handles MyBase.Load
        studentCount = 0
        studentRatingComboBox.DataSource = ratings
        DisplayBarChart()
    End Sub

    Private Sub submitButton_Click(ByVal sender As Object,
        ByVal e As System.EventArgs) Handles submitButton.Click

        Dim count As Integer = Val(studentRatingComboBox.Text)
        studentCount += 1
    End Sub

    Sub DisplayBarChart()

        'display the output header
        barChartListBox.Items.Add(
            "Rating" & vbTab & "Frequency")
        For count = 0 To frequency.GetUpperBound(0)
            Dim bar As String

            If count = 0 Then
                bar = String.Format("{0, 0}", 1)
            Else
                bar = String.Format("{0,0}", count + 1)
            End If

            For stars = 1 To frequency(count)
                bar &= ("*")
            Next

            barChartListBox.Items.Add(bar)
        Next count
    End Sub
End Class
For i As Integer = 1 To 10
    barChartListBox.Items.Add(New String("*", i))
Next

adds
*
**
***
****
*****
******
*******
********
*********
**********
to the listbox. I comes out nicer with the Courier New font

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.