VB.NET

Moderators: seancampbell
Number of threads: 4022
Number of posts: 10035

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Help with programming code. Posted by laajay9 on 11 Nov 2012 at 4:58 PM
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?



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.