Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,087 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,754 people online right now. Registration is fast and FREE... Join Now!




Test Score Problem

 
Reply to this topicStart new topic

Test Score Problem, problem

cardswin12
5 May, 2008 - 06:19 AM
Post #1

New D.I.C Head
*

Joined: 14 Feb, 2008
Posts: 9

vb

Public Class frmAverage
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnHeader2 As System.Windows.Forms.ColumnHeader
Friend WithEvents lstTestScores As System.Windows.Forms.ListView
Friend WithEvents btnEnterScores As System.Windows.Forms.Button
Friend WithEvents btnComputeAverage As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.lstTestScores = New System.Windows.Forms.ListView
Me.ColumnHeader1 = New System.Windows.Forms.ColumnHeader
Me.ColumnHeader2 = New System.Windows.Forms.ColumnHeader
Me.btnEnterScores = New System.Windows.Forms.Button
Me.btnComputeAverage = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'lstTestScores
'
Me.lstTestScores.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.lstTestScores.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader2})
Me.lstTestScores.FullRowSelect = True
Me.lstTestScores.Location = New System.Drawing.Point(0, 0)
Me.lstTestScores.MultiSelect = False
Me.lstTestScores.Name = "lstTestScores"
Me.lstTestScores.Size = New System.Drawing.Size(296, 144)
Me.lstTestScores.TabIndex = 0
Me.lstTestScores.View = System.Windows.Forms.View.Details
'
'ColumnHeader1
'
Me.ColumnHeader1.Text = "Student Name"
Me.ColumnHeader1.Width = 200
'
'ColumnHeader2
'
Me.ColumnHeader2.Text = "Test Score"
Me.ColumnHeader2.Width = 92
'
'btnEnterScores
'
Me.btnEnterScores.Anchor = System.Windows.Forms.AnchorStyles.Bottom
Me.btnEnterScores.Location = New System.Drawing.Point(30, 160)
Me.btnEnterScores.Name = "btnEnterScores"
Me.btnEnterScores.Size = New System.Drawing.Size(68, 40)
Me.btnEnterScores.TabIndex = 1
Me.btnEnterScores.Text = "Enter Test Scores"
'
'btnComputeAverage
'
Me.btnComputeAverage.Anchor = System.Windows.Forms.AnchorStyles.Bottom
Me.btnComputeAverage.Location = New System.Drawing.Point(198, 160)
Me.btnComputeAverage.Name = "btnComputeAverage"
Me.btnComputeAverage.Size = New System.Drawing.Size(68, 40)
Me.btnComputeAverage.TabIndex = 2
Me.btnComputeAverage.Text = "Compute Average"
'
'frmAverage
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(296, 206)
Me.Controls.Add(Me.btnComputeAverage)
Me.Controls.Add(Me.btnEnterScores)
Me.Controls.Add(Me.lstTestScores)
Me.Name = "frmAverage"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Test Score Average"
Me.ResumeLayout(False)

End Sub

#End Region
' Chapter 6: Test Score Average - Test Score Average Form
' Programmer: T. Adragna
' Date: May 4, 2008
Private Sub btnEnterScores_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnterScores.Click
Dim objEnterScoresForm As New frmEnterScores

objEnterScoresForm.ShowDialog()
Do Until objEnterScoresForm.txtStudentName.Text = ""
Dim lviScore As New ListViewItem(objEnterScoresForm.txtStudentName.Text)

lviScore.SubItems.Add(Convert.ToString(objEnterScoresForm.nudTestScore.Value))
lstTestScores.Items.Add(lviScore)
objEnterScoresForm.ShowDialog()

Loop
End Sub

Private Sub btnComputeAverage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnComputeAverage.Click
Dim intIndex, intListCount As Integer
Dim sngTotalScores As Single = 0
Dim sngAverageScore As Single = 0
Dim strScore As String, strResults As String
Dim dontLike As Integer
Dim n As Integer
Dim objEnterScoresForm As New frmEnterScores
Dim lviScore As New ListViewItem(objEnterScoresForm.txtStudentName.Text)

intListCount = Convert.ToInt32(lstTestScores.Items.Count)
For intIndex = 0 To intListCount - 1
strScore = lstTestScores.Items(intIndex).SubItems(1).Text
sngTotalScores += Convert.ToSingle(strScore)
Next

sngAverageScore = sngTotalScores / intListCount
strResults = "Average test score: " & Convert.ToString(sngAverageScore) & ControlChars.NewLine
If objEnterScoresForm.nudTestScore.Value() < 60 Then
n = 1
strResults &= (n / intListCount) * 100 & " percent"
End If

MessageBox.Show(strResults, "Test Score Average")
End Sub

Private Sub lstTestScores_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles lstTestScores.KeyDown
If e.KeyCode = Keys.D And lstTestScores.SelectedIndices.Count > 0 Then
lstTestScores.Items.RemoveAt(lstTestScores.SelectedIndices(0))
End If
End Sub

Private Sub frmAverage_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
Dim intColumn0Width As Integer

intColumn0Width = Me.Width - lstTestScores.Columns(1).Width - 12
If intColumn0Width > 0 Then
lstTestScores.Columns(0).Width = intColumn0Width
End If
End Sub

Private Sub frmAverage_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub lstTestScores_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstTestScores.SelectedIndexChanged

End Sub
End Class



I have to make it show up in a message box the percent of kids that got over 60 percent and the percent that got under 60 percent. I am having problems with hte percentage part if anybody could help me.

EDIT: Code blocks added => code.gif

This post has been edited by PsychoCoder: 5 May, 2008 - 06:23 AM
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Test Score Problem
5 May, 2008 - 08:51 AM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,319



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Can you describe what specifically you are having trouble with?

Is it the calculation or display of the percentages?
User is offlineProfile CardPM
+Quote Post

cardswin12
RE: Test Score Problem
6 May, 2008 - 05:49 AM
Post #3

New D.I.C Head
*

Joined: 14 Feb, 2008
Posts: 9

I am having trouble calculating it in visual basic. sad.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 11:55PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month