Quantcast
Channel: Programmers Heaven Forums RSS Feed
Viewing all articles
Browse latest Browse all 2703

Help with programming code.

$
0
0
I have to create a program where a user inputs a set of quiz scores and when they press the button on my form, it will display he frequency of occurrence of each score in a histogram using asterisks and then display the mean. This is what I have so far:

Public Class Form1

Dim quizScores() As Integer
Dim maximumScore As String

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'Purpose: Allows user to input the Maximum Quiz Score.
maximumScore = InputBox("Enter the Maximum Quiz Score:", "Maximum Quiz Score", , , )
ReDim quizScores(CInt(maximumScore))
End Sub

Private Sub txtmaxScore_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtmaxScore.KeyUp
'Purpose: Allows user to enter the Quiz Scores and counts the frequency of occurence of each score.
Dim score As Integer
If e.KeyCode = Keys.Enter Then
If (IsNumeric(txtmaxScore.Text)) _
AndAlso (CInt(txtmaxScore.Text)) >= 0 _
AndAlso CInt(txtmaxScore.Text) <= CInt(maximumScore) Then
score = CInt(txtmaxScore.Text)
lstDisplay.Items.Add(score)
Else
MessageBox.Show("Input must be an integer in the range 0 to " & maximumScore & "!", "ERROR!")
txtmaxScore.Clear()
txtmaxScore.Focus()
End If
txtmaxScore.Clear()
txtmaxScore.Focus()
End If
quizScores(CInt(txtmaxScore.Text)) += 1
End Sub

Private Sub btnDisplay_Click(sender As System.Object, e As System.EventArgs) Handles btnDisplay.Click
'Purpose: To display the mean of the data set and a histogram of the frequency of occurence.
Dim Total As Double = 0.0
Dim Average As Double
Dim Count As Integer
For Count = 0 To CInt(maximumScore)
Total += quizScores(CInt(txtmaxScore.Text))
Next Count
Average = Total / quizScores(CInt(txtmaxScore.Text))
Dim n As Integer = CInt("*")
For quizScores(CInt(txtmaxScore.Text)) = 0 To CInt(maximumScore)
Print(CInt(CInt(txtmaxScore.Text) & ":|" & (quizScores(n))))
Next quizScores(CInt(txtmaxScore.Text))
lstDisplay.Items.Add("Mean = " & Average)
End Sub

Private Sub btnClear_Click(sender As System.Object, e As System.EventArgs) Handles btnClear.Click
'Purpose: To clear the form.
txtmaxScore.Clear()
lstDisplay.Items.Clear()
txtmaxScore.Focus()
End Sub

End Class

And I am stuck. I cannot even debug the program because I am getting a conversion to string error. Can someone help?

Viewing all articles
Browse latest Browse all 2703

Trending Articles