471,616 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,616 software developers and data experts.

2 small questions about a project

TBK
I'm trying to finish up an assignment I had for a class and basically I'm
stuck. The program is supposed to take information you've entered, put it
into an array, display it in a listbox and then average the total of numbers.
Right now I have 2 questions. How do I get numbers from my array that are
put into the listbox into the 2 decimal format. I've tried all sorts of
combinations and I can't get it to work. Second, I need to take the total of
the numbers that are entered into the listbox and constantly average them
everytime I hit the submit button. Here's my code, any help would be greatly
appreciated:

Public Class frmRyanStudentGrades
Inherits System.Windows.Forms.Form
'Define instance variables
Dim m_intCounter As Integer = 0
Dim m_strDisplayInfo(,) As String = New String(10, 1) {}

#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 fraInputGrade As System.Windows.Forms.GroupBox
Friend WithEvents lblStudentName As System.Windows.Forms.Label
Friend WithEvents lblTest1 As System.Windows.Forms.Label
Friend WithEvents lblTest2 As System.Windows.Forms.Label
Friend WithEvents lblTest3 As System.Windows.Forms.Label
Friend WithEvents lblClassAverage As System.Windows.Forms.Label
Friend WithEvents lblClassAverageResult As System.Windows.Forms.Label
Friend WithEvents lstNameGradeDisplay As System.Windows.Forms.ListBox
Friend WithEvents txtStudentName As System.Windows.Forms.TextBox
Friend WithEvents txtTest1 As System.Windows.Forms.TextBox
Friend WithEvents txtTest2 As System.Windows.Forms.TextBox
Friend WithEvents txtTest3 As System.Windows.Forms.TextBox
Friend WithEvents btnSubmitGrade As System.Windows.Forms.Button
Friend WithEvents btnStartOver As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.fraInputGrade = New System.Windows.Forms.GroupBox
Me.lblStudentName = New System.Windows.Forms.Label
Me.lblTest1 = New System.Windows.Forms.Label
Me.lblTest2 = New System.Windows.Forms.Label
Me.lblTest3 = New System.Windows.Forms.Label
Me.lblClassAverage = New System.Windows.Forms.Label
Me.lblClassAverageResult = New System.Windows.Forms.Label
Me.lstNameGradeDisplay = New System.Windows.Forms.ListBox
Me.txtStudentName = New System.Windows.Forms.TextBox
Me.txtTest1 = New System.Windows.Forms.TextBox
Me.txtTest2 = New System.Windows.Forms.TextBox
Me.txtTest3 = New System.Windows.Forms.TextBox
Me.btnSubmitGrade = New System.Windows.Forms.Button
Me.btnStartOver = New System.Windows.Forms.Button
Me.fraInputGrade.SuspendLayout()
Me.SuspendLayout()
'
'fraInputGrade
'
Me.fraInputGrade.Controls.Add(Me.btnStartOver)
Me.fraInputGrade.Controls.Add(Me.btnSubmitGrade)
Me.fraInputGrade.Controls.Add(Me.txtTest3)
Me.fraInputGrade.Controls.Add(Me.txtTest2)
Me.fraInputGrade.Controls.Add(Me.txtTest1)
Me.fraInputGrade.Controls.Add(Me.txtStudentName)
Me.fraInputGrade.Controls.Add(Me.lblTest3)
Me.fraInputGrade.Controls.Add(Me.lblTest2)
Me.fraInputGrade.Controls.Add(Me.lblTest1)
Me.fraInputGrade.Controls.Add(Me.lblStudentName)
Me.fraInputGrade.Location = New System.Drawing.Point(8, 8)
Me.fraInputGrade.Name = "fraInputGrade"
Me.fraInputGrade.Size = New System.Drawing.Size(256, 208)
Me.fraInputGrade.TabIndex = 0
Me.fraInputGrade.TabStop = False
Me.fraInputGrade.Text = "Input Grade"
'
'lblStudentName
'
Me.lblStudentName.Location = New System.Drawing.Point(8, 31)
Me.lblStudentName.Name = "lblStudentName"
Me.lblStudentName.Size = New System.Drawing.Size(80, 23)
Me.lblStudentName.TabIndex = 0
Me.lblStudentName.Text = "Student Name:"
'
'lblTest1
'
Me.lblTest1.Location = New System.Drawing.Point(8, 63)
Me.lblTest1.Name = "lblTest1"
Me.lblTest1.Size = New System.Drawing.Size(40, 23)
Me.lblTest1.TabIndex = 1
Me.lblTest1.Text = "Test 1:"
'
'lblTest2
'
Me.lblTest2.Location = New System.Drawing.Point(8, 91)
Me.lblTest2.Name = "lblTest2"
Me.lblTest2.Size = New System.Drawing.Size(40, 23)
Me.lblTest2.TabIndex = 2
Me.lblTest2.Text = "Test 2:"
'
'lblTest3
'
Me.lblTest3.Location = New System.Drawing.Point(8, 119)
Me.lblTest3.Name = "lblTest3"
Me.lblTest3.Size = New System.Drawing.Size(40, 23)
Me.lblTest3.TabIndex = 3
Me.lblTest3.Text = "Test 3:"
'
'lblClassAverage
'
Me.lblClassAverage.Location = New System.Drawing.Point(272, 184)
Me.lblClassAverage.Name = "lblClassAverage"
Me.lblClassAverage.Size = New System.Drawing.Size(88, 23)
Me.lblClassAverage.TabIndex = 4
Me.lblClassAverage.Text = "Class Average:"
Me.lblClassAverage.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft
'
'lblClassAverageResult
'
Me.lblClassAverageResult.BorderStyle =
System.Windows.Forms.BorderStyle.Fixed3D
Me.lblClassAverageResult.Location = New System.Drawing.Point(424, 184)
Me.lblClassAverageResult.Name = "lblClassAverageResult"
Me.lblClassAverageResult.Size = New System.Drawing.Size(56, 23)
Me.lblClassAverageResult.TabIndex = 4
Me.lblClassAverageResult.TextAlign =
System.Drawing.ContentAlignment.MiddleCenter
'
'lstNameGradeDisplay
'
Me.lstNameGradeDisplay.Location = New System.Drawing.Point(280, 16)
Me.lstNameGradeDisplay.Name = "lstNameGradeDisplay"
Me.lstNameGradeDisplay.Size = New System.Drawing.Size(200, 160)
Me.lstNameGradeDisplay.TabIndex = 5
Me.lstNameGradeDisplay.TabStop = False
'
'txtStudentName
'
Me.txtStudentName.Location = New System.Drawing.Point(96, 32)
Me.txtStudentName.Name = "txtStudentName"
Me.txtStudentName.Size = New System.Drawing.Size(152, 20)
Me.txtStudentName.TabIndex = 4
Me.txtStudentName.Text = ""
Me.txtStudentName.TextAlign =
System.Windows.Forms.HorizontalAlignment.Right
'
'txtTest1
'
Me.txtTest1.Location = New System.Drawing.Point(192, 64)
Me.txtTest1.MaxLength = 3
Me.txtTest1.Name = "txtTest1"
Me.txtTest1.Size = New System.Drawing.Size(56, 20)
Me.txtTest1.TabIndex = 5
Me.txtTest1.Text = ""
Me.txtTest1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
'
'txtTest2
'
Me.txtTest2.Location = New System.Drawing.Point(192, 92)
Me.txtTest2.MaxLength = 3
Me.txtTest2.Name = "txtTest2"
Me.txtTest2.Size = New System.Drawing.Size(56, 20)
Me.txtTest2.TabIndex = 6
Me.txtTest2.Text = ""
Me.txtTest2.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
'
'txtTest3
'
Me.txtTest3.Location = New System.Drawing.Point(192, 120)
Me.txtTest3.MaxLength = 3
Me.txtTest3.Name = "txtTest3"
Me.txtTest3.Size = New System.Drawing.Size(56, 20)
Me.txtTest3.TabIndex = 7
Me.txtTest3.Text = ""
Me.txtTest3.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
'
'btnSubmitGrade
'
Me.btnSubmitGrade.Location = New System.Drawing.Point(160, 176)
Me.btnSubmitGrade.Name = "btnSubmitGrade"
Me.btnSubmitGrade.Size = New System.Drawing.Size(88, 23)
Me.btnSubmitGrade.TabIndex = 8
Me.btnSubmitGrade.Text = "Submit Grade"
'
'btnStartOver
'
Me.btnStartOver.Enabled = False
Me.btnStartOver.Location = New System.Drawing.Point(8, 176)
Me.btnStartOver.Name = "btnStartOver"
Me.btnStartOver.TabIndex = 9
Me.btnStartOver.Text = "Start Over"
'
'frmRyanStudentGrades
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(496, 221)
Me.Controls.Add(Me.lstNameGradeDisplay)
Me.Controls.Add(Me.fraInputGrade)
Me.Controls.Add(Me.lblClassAverage)
Me.Controls.Add(Me.lblClassAverageResult)
Me.Name = "frmRyanStudentGrades"
Me.Text = "Ryan Student Grades"
Me.fraInputGrade.ResumeLayout(False)
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub btnSubmitGrade_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnSubmitGrade.Click
'Define Variables
Dim strStudentName As String = txtStudentName.Text
'Display errors if data isn't entered
If txtStudentName.Text = "" Or txtTest1.Text = "" Or txtTest2.Text =
"" _
Or txtTest3.Text = "" Then
MessageBox.Show("Please fill in all fields", "Missing
Information", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
'Go through array cases
m_intCounter += 1
Select Case m_intCounter
Case Is = 1
m_strDisplayInfo(m_intCounter, 0) = strStudentName
m_strDisplayInfo(m_intCounter, 1) = AverageGrade()
Case Is = 2
m_strDisplayInfo(m_intCounter, 0) = strStudentName
m_strDisplayInfo(m_intCounter, 1) = AverageGrade()
Case Is = 3
m_strDisplayInfo(m_intCounter, 0) = strStudentName
m_strDisplayInfo(m_intCounter, 1) = AverageGrade()
Case Is = 4
m_strDisplayInfo(m_intCounter, 0) = strStudentName
m_strDisplayInfo(m_intCounter, 1) = AverageGrade()
Case Is = 5
m_strDisplayInfo(m_intCounter, 0) = strStudentName
m_strDisplayInfo(m_intCounter, 1) = AverageGrade()
Case Is = 6
m_strDisplayInfo(m_intCounter, 0) = strStudentName
m_strDisplayInfo(m_intCounter, 1) = AverageGrade()
Case Is = 7
m_strDisplayInfo(m_intCounter, 0) = strStudentName
m_strDisplayInfo(m_intCounter, 1) = AverageGrade()
Case Is = 8
m_strDisplayInfo(m_intCounter, 0) = strStudentName
m_strDisplayInfo(m_intCounter, 1) = AverageGrade()
Case Is = 9
m_strDisplayInfo(m_intCounter, 0) = strStudentName
m_strDisplayInfo(m_intCounter, 1) = AverageGrade()
Case Is = 10
m_strDisplayInfo(m_intCounter, 0) = strStudentName
m_strDisplayInfo(m_intCounter, 1) = AverageGrade()
btnSubmitGrade.Enabled = False
btnStartOver.Enabled = True
End Select
'Display data, reset focus to the top
txtStudentName.Focus()
lstNameGradeDisplay.Items.Add(strStudentName & ControlChars.Tab
& AverageGrade())
lblClassAverageResult.Text = String.Format("{0:F}",
TotalAverage())
End If
End Sub
Function TotalAverage() As Double
'Define Variables
Dim dblClassAverage As Double
dblClassAverage = m_strDisplayInfo(m_intCounter, 1)
Return (dblClassAverage / m_intCounter)
End Function
Function AverageGrade() As Decimal
'Function to average the 3 test grades
'Define Variables
Dim decTest1 As Decimal = Val(txtTest1.Text)
Dim decTest2 As Decimal = Val(txtTest2.Text)
Dim decTest3 As Decimal = Val(txtTest3.Text)
Dim decAverage As Decimal
decAverage = decTest1 + decTest2 + decTest3
Return (decAverage / 3)
End Function

Private Sub btnStartOver_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnStartOver.Click
'Starts the program over
m_intCounter = 0
btnSubmitGrade.Enabled = True
btnStartOver.Enabled = False
lstNameGradeDisplay.Items.Clear()
txtStudentName.Text = ""
txtTest1.Text = ""
txtTest2.Text = ""
txtTest3.Text = ""
lblClassAverageResult.Text = ""
txtStudentName.Focus()
End Sub
End Class
Nov 21 '05 #1
1 1185
Hint #1: Use ArrayList to store the strings (you can use the .add method)
instead of an array so you don't have to redim the array each time a number
is added.

Hint #2: Use DirectCast(myArrayList(i), double) to sum the numbers

Hint #3: Use .ToString and .Format methods to display the number as two
decimal places.
"TBK" wrote:
I'm trying to finish up an assignment I had for a class and basically I'm
stuck. The program is supposed to take information you've entered, put it
into an array, display it in a listbox and then average the total of numbers.
Right now I have 2 questions. How do I get numbers from my array that are
put into the listbox into the 2 decimal format. I've tried all sorts of
combinations and I can't get it to work. Second, I need to take the total of
the numbers that are entered into the listbox and constantly average them
everytime I hit the submit button. Here's my code, any help would be greatly
appreciated:

Public Class frmRyanStudentGrades
Inherits System.Windows.Forms.Form
'Define instance variables
Dim m_intCounter As Integer = 0
Dim m_strDisplayInfo(,) As String = New String(10, 1) {}

#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 fraInputGrade As System.Windows.Forms.GroupBox
Friend WithEvents lblStudentName As System.Windows.Forms.Label
Friend WithEvents lblTest1 As System.Windows.Forms.Label
Friend WithEvents lblTest2 As System.Windows.Forms.Label
Friend WithEvents lblTest3 As System.Windows.Forms.Label
Friend WithEvents lblClassAverage As System.Windows.Forms.Label
Friend WithEvents lblClassAverageResult As System.Windows.Forms.Label
Friend WithEvents lstNameGradeDisplay As System.Windows.Forms.ListBox
Friend WithEvents txtStudentName As System.Windows.Forms.TextBox
Friend WithEvents txtTest1 As System.Windows.Forms.TextBox
Friend WithEvents txtTest2 As System.Windows.Forms.TextBox
Friend WithEvents txtTest3 As System.Windows.Forms.TextBox
Friend WithEvents btnSubmitGrade As System.Windows.Forms.Button
Friend WithEvents btnStartOver As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.fraInputGrade = New System.Windows.Forms.GroupBox
Me.lblStudentName = New System.Windows.Forms.Label
Me.lblTest1 = New System.Windows.Forms.Label
Me.lblTest2 = New System.Windows.Forms.Label
Me.lblTest3 = New System.Windows.Forms.Label
Me.lblClassAverage = New System.Windows.Forms.Label
Me.lblClassAverageResult = New System.Windows.Forms.Label
Me.lstNameGradeDisplay = New System.Windows.Forms.ListBox
Me.txtStudentName = New System.Windows.Forms.TextBox
Me.txtTest1 = New System.Windows.Forms.TextBox
Me.txtTest2 = New System.Windows.Forms.TextBox
Me.txtTest3 = New System.Windows.Forms.TextBox
Me.btnSubmitGrade = New System.Windows.Forms.Button
Me.btnStartOver = New System.Windows.Forms.Button
Me.fraInputGrade.SuspendLayout()
Me.SuspendLayout()
'
'fraInputGrade
'
Me.fraInputGrade.Controls.Add(Me.btnStartOver)
Me.fraInputGrade.Controls.Add(Me.btnSubmitGrade)
Me.fraInputGrade.Controls.Add(Me.txtTest3)
Me.fraInputGrade.Controls.Add(Me.txtTest2)
Me.fraInputGrade.Controls.Add(Me.txtTest1)
Me.fraInputGrade.Controls.Add(Me.txtStudentName)
Me.fraInputGrade.Controls.Add(Me.lblTest3)
Me.fraInputGrade.Controls.Add(Me.lblTest2)
Me.fraInputGrade.Controls.Add(Me.lblTest1)
Me.fraInputGrade.Controls.Add(Me.lblStudentName)
Me.fraInputGrade.Location = New System.Drawing.Point(8, 8)
Me.fraInputGrade.Name = "fraInputGrade"
Me.fraInputGrade.Size = New System.Drawing.Size(256, 208)
Me.fraInputGrade.TabIndex = 0
Me.fraInputGrade.TabStop = False
Me.fraInputGrade.Text = "Input Grade"
'
'lblStudentName
'
Me.lblStudentName.Location = New System.Drawing.Point(8, 31)
Me.lblStudentName.Name = "lblStudentName"
Me.lblStudentName.Size = New System.Drawing.Size(80, 23)
Me.lblStudentName.TabIndex = 0
Me.lblStudentName.Text = "Student Name:"
'
'lblTest1
'
Me.lblTest1.Location = New System.Drawing.Point(8, 63)
Me.lblTest1.Name = "lblTest1"
Me.lblTest1.Size = New System.Drawing.Size(40, 23)
Me.lblTest1.TabIndex = 1
Me.lblTest1.Text = "Test 1:"
'
'lblTest2
'
Me.lblTest2.Location = New System.Drawing.Point(8, 91)
Me.lblTest2.Name = "lblTest2"
Me.lblTest2.Size = New System.Drawing.Size(40, 23)
Me.lblTest2.TabIndex = 2
Me.lblTest2.Text = "Test 2:"
'
'lblTest3
'
Me.lblTest3.Location = New System.Drawing.Point(8, 119)
Me.lblTest3.Name = "lblTest3"
Me.lblTest3.Size = New System.Drawing.Size(40, 23)
Me.lblTest3.TabIndex = 3
Me.lblTest3.Text = "Test 3:"
'
'lblClassAverage
'
Me.lblClassAverage.Location = New System.Drawing.Point(272, 184)
Me.lblClassAverage.Name = "lblClassAverage"
Me.lblClassAverage.Size = New System.Drawing.Size(88, 23)
Me.lblClassAverage.TabIndex = 4
Me.lblClassAverage.Text = "Class Average:"
Me.lblClassAverage.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft
'
'lblClassAverageResult
'
Me.lblClassAverageResult.BorderStyle =
System.Windows.Forms.BorderStyle.Fixed3D
Me.lblClassAverageResult.Location = New System.Drawing.Point(424, 184)
Me.lblClassAverageResult.Name = "lblClassAverageResult"
Me.lblClassAverageResult.Size = New System.Drawing.Size(56, 23)
Me.lblClassAverageResult.TabIndex = 4
Me.lblClassAverageResult.TextAlign =
System.Drawing.ContentAlignment.MiddleCenter
'
'lstNameGradeDisplay
'
Me.lstNameGradeDisplay.Location = New System.Drawing.Point(280, 16)
Me.lstNameGradeDisplay.Name = "lstNameGradeDisplay"
Me.lstNameGradeDisplay.Size = New System.Drawing.Size(200, 160)
Me.lstNameGradeDisplay.TabIndex = 5
Me.lstNameGradeDisplay.TabStop = False
'
'txtStudentName
'
Me.txtStudentName.Location = New System.Drawing.Point(96, 32)
Me.txtStudentName.Name = "txtStudentName"
Me.txtStudentName.Size = New System.Drawing.Size(152, 20)
Me.txtStudentName.TabIndex = 4
Me.txtStudentName.Text = ""
Me.txtStudentName.TextAlign =
System.Windows.Forms.HorizontalAlignment.Right
'
'txtTest1
'
Me.txtTest1.Location = New System.Drawing.Point(192, 64)
Me.txtTest1.MaxLength = 3
Me.txtTest1.Name = "txtTest1"
Me.txtTest1.Size = New System.Drawing.Size(56, 20)
Me.txtTest1.TabIndex = 5
Me.txtTest1.Text = ""
Me.txtTest1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
'
'txtTest2
'
Me.txtTest2.Location = New System.Drawing.Point(192, 92)
Me.txtTest2.MaxLength = 3
Me.txtTest2.Name = "txtTest2"
Me.txtTest2.Size = New System.Drawing.Size(56, 20)
Me.txtTest2.TabIndex = 6
Me.txtTest2.Text = ""
Me.txtTest2.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
'
'txtTest3
'
Me.txtTest3.Location = New System.Drawing.Point(192, 120)
Me.txtTest3.MaxLength = 3
Me.txtTest3.Name = "txtTest3"
Me.txtTest3.Size = New System.Drawing.Size(56, 20)
Me.txtTest3.TabIndex = 7
Me.txtTest3.Text = ""
Me.txtTest3.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
'
'btnSubmitGrade
'
Me.btnSubmitGrade.Location = New System.Drawing.Point(160, 176)
Me.btnSubmitGrade.Name = "btnSubmitGrade"
Me.btnSubmitGrade.Size = New System.Drawing.Size(88, 23)
Me.btnSubmitGrade.TabIndex = 8
Me.btnSubmitGrade.Text = "Submit Grade"
'
'btnStartOver
'
Me.btnStartOver.Enabled = False
Me.btnStartOver.Location = New System.Drawing.Point(8, 176)
Me.btnStartOver.Name = "btnStartOver"
Me.btnStartOver.TabIndex = 9
Me.btnStartOver.Text = "Start Over"
'
'frmRyanStudentGrades
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(496, 221)
Me.Controls.Add(Me.lstNameGradeDisplay)
Me.Controls.Add(Me.fraInputGrade)
Me.Controls.Add(Me.lblClassAverage)
Me.Controls.Add(Me.lblClassAverageResult)
Me.Name = "frmRyanStudentGrades"
Me.Text = "Ryan Student Grades"
Me.fraInputGrade.ResumeLayout(False)
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub btnSubmitGrade_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnSubmitGrade.Click
'Define Variables
Dim strStudentName As String = txtStudentName.Text
'Display errors if data isn't entered
If txtStudentName.Text = "" Or txtTest1.Text = "" Or txtTest2.Text =
"" _
Or txtTest3.Text = "" Then
MessageBox.Show("Please fill in all fields", "Missing
Information", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
'Go through array cases
m_intCounter += 1
Select Case m_intCounter
Case Is = 1
m_strDisplayInfo(m_intCounter, 0) = strStudentName
m_strDisplayInfo(m_intCounter, 1) = AverageGrade()
Case Is = 2
m_strDisplayInfo(m_intCounter, 0) = strStudentName
m_strDisplayInfo(m_intCounter, 1) = AverageGrade()
Case Is = 3
m_strDisplayInfo(m_intCounter, 0) = strStudentName
m_strDisplayInfo(m_intCounter, 1) = AverageGrade()
Case Is = 4
m_strDisplayInfo(m_intCounter, 0) = strStudentName
m_strDisplayInfo(m_intCounter, 1) = AverageGrade()
Case Is = 5
m_strDisplayInfo(m_intCounter, 0) = strStudentName
m_strDisplayInfo(m_intCounter, 1) = AverageGrade()
Case Is = 6
m_strDisplayInfo(m_intCounter, 0) = strStudentName
m_strDisplayInfo(m_intCounter, 1) = AverageGrade()
Case Is = 7
m_strDisplayInfo(m_intCounter, 0) = strStudentName
m_strDisplayInfo(m_intCounter, 1) = AverageGrade()
Case Is = 8
m_strDisplayInfo(m_intCounter, 0) = strStudentName
m_strDisplayInfo(m_intCounter, 1) = AverageGrade()
Case Is = 9
m_strDisplayInfo(m_intCounter, 0) = strStudentName
m_strDisplayInfo(m_intCounter, 1) = AverageGrade()
Case Is = 10
m_strDisplayInfo(m_intCounter, 0) = strStudentName
m_strDisplayInfo(m_intCounter, 1) = AverageGrade()
btnSubmitGrade.Enabled = False
btnStartOver.Enabled = True
End Select
'Display data, reset focus to the top
txtStudentName.Focus()
lstNameGradeDisplay.Items.Add(strStudentName & ControlChars.Tab
& AverageGrade())
lblClassAverageResult.Text = String.Format("{0:F}",
TotalAverage())
End If
End Sub
Function TotalAverage() As Double
'Define Variables
Dim dblClassAverage As Double
dblClassAverage = m_strDisplayInfo(m_intCounter, 1)
Return (dblClassAverage / m_intCounter)
End Function
Function AverageGrade() As Decimal
'Function to average the 3 test grades
'Define Variables
Dim decTest1 As Decimal = Val(txtTest1.Text)
Dim decTest2 As Decimal = Val(txtTest2.Text)
Dim decTest3 As Decimal = Val(txtTest3.Text)
Dim decAverage As Decimal
decAverage = decTest1 + decTest2 + decTest3
Return (decAverage / 3)
End Function

Private Sub btnStartOver_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnStartOver.Click
'Starts the program over
m_intCounter = 0
btnSubmitGrade.Enabled = True
btnStartOver.Enabled = False
lstNameGradeDisplay.Items.Clear()
txtStudentName.Text = ""
txtTest1.Text = ""
txtTest2.Text = ""
txtTest3.Text = ""
lblClassAverageResult.Text = ""
txtStudentName.Focus()
End Sub
End Class

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

27 posts views Thread by Jatinder | last post: by
7 posts views Thread by MattB | last post: by
4 posts views Thread by =?Utf-8?B?VzFsZDBuZTc0?= | last post: by
169 posts views Thread by JohnQ | last post: by
6 posts views Thread by =?Utf-8?B?Qm9ucw==?= | last post: by
reply views Thread by leo001 | last post: by
1 post views Thread by ZEDKYRIE | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.