473,856 Members | 1,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 frmRyanStudentG rades
Inherits System.Windows. Forms.Form
'Define instance variables
Dim m_intCounter As Integer = 0
Dim m_strDisplayInf o(,) 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.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() 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.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'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 lblClassAverage Result As System.Windows. Forms.Label
Friend WithEvents lstNameGradeDis play 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.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.fraInputGrad e = New System.Windows. Forms.GroupBox
Me.lblStudentNa me = 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.lblClassAver age = New System.Windows. Forms.Label
Me.lblClassAver ageResult = New System.Windows. Forms.Label
Me.lstNameGrade Display = New System.Windows. Forms.ListBox
Me.txtStudentNa me = 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.btnSubmitGra de = New System.Windows. Forms.Button
Me.btnStartOver = New System.Windows. Forms.Button
Me.fraInputGrad e.SuspendLayout ()
Me.SuspendLayou t()
'
'fraInputGrade
'
Me.fraInputGrad e.Controls.Add( Me.btnStartOver )
Me.fraInputGrad e.Controls.Add( Me.btnSubmitGra de)
Me.fraInputGrad e.Controls.Add( Me.txtTest3)
Me.fraInputGrad e.Controls.Add( Me.txtTest2)
Me.fraInputGrad e.Controls.Add( Me.txtTest1)
Me.fraInputGrad e.Controls.Add( Me.txtStudentNa me)
Me.fraInputGrad e.Controls.Add( Me.lblTest3)
Me.fraInputGrad e.Controls.Add( Me.lblTest2)
Me.fraInputGrad e.Controls.Add( Me.lblTest1)
Me.fraInputGrad e.Controls.Add( Me.lblStudentNa me)
Me.fraInputGrad e.Location = New System.Drawing. Point(8, 8)
Me.fraInputGrad e.Name = "fraInputGr ade"
Me.fraInputGrad e.Size = New System.Drawing. Size(256, 208)
Me.fraInputGrad e.TabIndex = 0
Me.fraInputGrad e.TabStop = False
Me.fraInputGrad e.Text = "Input Grade"
'
'lblStudentName
'
Me.lblStudentNa me.Location = New System.Drawing. Point(8, 31)
Me.lblStudentNa me.Name = "lblStudentName "
Me.lblStudentNa me.Size = New System.Drawing. Size(80, 23)
Me.lblStudentNa me.TabIndex = 0
Me.lblStudentNa me.Text = "Student Name:"
'
'lblTest1
'
Me.lblTest1.Loc ation = New System.Drawing. Point(8, 63)
Me.lblTest1.Nam e = "lblTest1"
Me.lblTest1.Siz e = New System.Drawing. Size(40, 23)
Me.lblTest1.Tab Index = 1
Me.lblTest1.Tex t = "Test 1:"
'
'lblTest2
'
Me.lblTest2.Loc ation = New System.Drawing. Point(8, 91)
Me.lblTest2.Nam e = "lblTest2"
Me.lblTest2.Siz e = New System.Drawing. Size(40, 23)
Me.lblTest2.Tab Index = 2
Me.lblTest2.Tex t = "Test 2:"
'
'lblTest3
'
Me.lblTest3.Loc ation = New System.Drawing. Point(8, 119)
Me.lblTest3.Nam e = "lblTest3"
Me.lblTest3.Siz e = New System.Drawing. Size(40, 23)
Me.lblTest3.Tab Index = 3
Me.lblTest3.Tex t = "Test 3:"
'
'lblClassAverag e
'
Me.lblClassAver age.Location = New System.Drawing. Point(272, 184)
Me.lblClassAver age.Name = "lblClassAverag e"
Me.lblClassAver age.Size = New System.Drawing. Size(88, 23)
Me.lblClassAver age.TabIndex = 4
Me.lblClassAver age.Text = "Class Average:"
Me.lblClassAver age.TextAlign =
System.Drawing. ContentAlignmen t.MiddleLeft
'
'lblClassAverag eResult
'
Me.lblClassAver ageResult.Borde rStyle =
System.Windows. Forms.BorderSty le.Fixed3D
Me.lblClassAver ageResult.Locat ion = New System.Drawing. Point(424, 184)
Me.lblClassAver ageResult.Name = "lblClassAverag eResult"
Me.lblClassAver ageResult.Size = New System.Drawing. Size(56, 23)
Me.lblClassAver ageResult.TabIn dex = 4
Me.lblClassAver ageResult.TextA lign =
System.Drawing. ContentAlignmen t.MiddleCenter
'
'lstNameGradeDi splay
'
Me.lstNameGrade Display.Locatio n = New System.Drawing. Point(280, 16)
Me.lstNameGrade Display.Name = "lstNameGradeDi splay"
Me.lstNameGrade Display.Size = New System.Drawing. Size(200, 160)
Me.lstNameGrade Display.TabInde x = 5
Me.lstNameGrade Display.TabStop = False
'
'txtStudentName
'
Me.txtStudentNa me.Location = New System.Drawing. Point(96, 32)
Me.txtStudentNa me.Name = "txtStudentName "
Me.txtStudentNa me.Size = New System.Drawing. Size(152, 20)
Me.txtStudentNa me.TabIndex = 4
Me.txtStudentNa me.Text = ""
Me.txtStudentNa me.TextAlign =
System.Windows. Forms.Horizonta lAlignment.Righ t
'
'txtTest1
'
Me.txtTest1.Loc ation = New System.Drawing. Point(192, 64)
Me.txtTest1.Max Length = 3
Me.txtTest1.Nam e = "txtTest1"
Me.txtTest1.Siz e = New System.Drawing. Size(56, 20)
Me.txtTest1.Tab Index = 5
Me.txtTest1.Tex t = ""
Me.txtTest1.Tex tAlign = System.Windows. Forms.Horizonta lAlignment.Righ t
'
'txtTest2
'
Me.txtTest2.Loc ation = New System.Drawing. Point(192, 92)
Me.txtTest2.Max Length = 3
Me.txtTest2.Nam e = "txtTest2"
Me.txtTest2.Siz e = New System.Drawing. Size(56, 20)
Me.txtTest2.Tab Index = 6
Me.txtTest2.Tex t = ""
Me.txtTest2.Tex tAlign = System.Windows. Forms.Horizonta lAlignment.Righ t
'
'txtTest3
'
Me.txtTest3.Loc ation = New System.Drawing. Point(192, 120)
Me.txtTest3.Max Length = 3
Me.txtTest3.Nam e = "txtTest3"
Me.txtTest3.Siz e = New System.Drawing. Size(56, 20)
Me.txtTest3.Tab Index = 7
Me.txtTest3.Tex t = ""
Me.txtTest3.Tex tAlign = System.Windows. Forms.Horizonta lAlignment.Righ t
'
'btnSubmitGrade
'
Me.btnSubmitGra de.Location = New System.Drawing. Point(160, 176)
Me.btnSubmitGra de.Name = "btnSubmitGrade "
Me.btnSubmitGra de.Size = New System.Drawing. Size(88, 23)
Me.btnSubmitGra de.TabIndex = 8
Me.btnSubmitGra de.Text = "Submit Grade"
'
'btnStartOver
'
Me.btnStartOver .Enabled = False
Me.btnStartOver .Location = New System.Drawing. Point(8, 176)
Me.btnStartOver .Name = "btnStartOv er"
Me.btnStartOver .TabIndex = 9
Me.btnStartOver .Text = "Start Over"
'
'frmRyanStudent Grades
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(496, 221)
Me.Controls.Add (Me.lstNameGrad eDisplay)
Me.Controls.Add (Me.fraInputGra de)
Me.Controls.Add (Me.lblClassAve rage)
Me.Controls.Add (Me.lblClassAve rageResult)
Me.Name = "frmRyanStudent Grades"
Me.Text = "Ryan Student Grades"
Me.fraInputGrad e.ResumeLayout( False)
Me.ResumeLayout (False)

End Sub

#End Region

Private Sub btnSubmitGrade_ Click(ByVal sender As System.Object, ByVal e
As System.EventArg s) 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", MessageBoxButto ns.OK, MessageBoxIcon. Error)
Else
'Go through array cases
m_intCounter += 1
Select Case m_intCounter
Case Is = 1
m_strDisplayInf o(m_intCounter, 0) = strStudentName
m_strDisplayInf o(m_intCounter, 1) = AverageGrade()
Case Is = 2
m_strDisplayInf o(m_intCounter, 0) = strStudentName
m_strDisplayInf o(m_intCounter, 1) = AverageGrade()
Case Is = 3
m_strDisplayInf o(m_intCounter, 0) = strStudentName
m_strDisplayInf o(m_intCounter, 1) = AverageGrade()
Case Is = 4
m_strDisplayInf o(m_intCounter, 0) = strStudentName
m_strDisplayInf o(m_intCounter, 1) = AverageGrade()
Case Is = 5
m_strDisplayInf o(m_intCounter, 0) = strStudentName
m_strDisplayInf o(m_intCounter, 1) = AverageGrade()
Case Is = 6
m_strDisplayInf o(m_intCounter, 0) = strStudentName
m_strDisplayInf o(m_intCounter, 1) = AverageGrade()
Case Is = 7
m_strDisplayInf o(m_intCounter, 0) = strStudentName
m_strDisplayInf o(m_intCounter, 1) = AverageGrade()
Case Is = 8
m_strDisplayInf o(m_intCounter, 0) = strStudentName
m_strDisplayInf o(m_intCounter, 1) = AverageGrade()
Case Is = 9
m_strDisplayInf o(m_intCounter, 0) = strStudentName
m_strDisplayInf o(m_intCounter, 1) = AverageGrade()
Case Is = 10
m_strDisplayInf o(m_intCounter, 0) = strStudentName
m_strDisplayInf o(m_intCounter, 1) = AverageGrade()
btnSubmitGrade. Enabled = False
btnStartOver.En abled = True
End Select
'Display data, reset focus to the top
txtStudentName. Focus()
lstNameGradeDis play.Items.Add( strStudentName & ControlChars.Ta b
& AverageGrade())
lblClassAverage Result.Text = String.Format(" {0:F}",
TotalAverage())
End If
End Sub
Function TotalAverage() As Double
'Define Variables
Dim dblClassAverage As Double
dblClassAverage = m_strDisplayInf o(m_intCounter, 1)
Return (dblClassAverag e / m_intCounter)
End Function
Function AverageGrade() As Decimal
'Function to average the 3 test grades
'Define Variables
Dim decTest1 As Decimal = Val(txtTest1.Te xt)
Dim decTest2 As Decimal = Val(txtTest2.Te xt)
Dim decTest3 As Decimal = Val(txtTest3.Te xt)
Dim decAverage As Decimal
decAverage = decTest1 + decTest2 + decTest3
Return (decAverage / 3)
End Function

Private Sub btnStartOver_Cl ick(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnStartOver.Cl ick
'Starts the program over
m_intCounter = 0
btnSubmitGrade. Enabled = True
btnStartOver.En abled = False
lstNameGradeDis play.Items.Clea r()
txtStudentName. Text = ""
txtTest1.Text = ""
txtTest2.Text = ""
txtTest3.Text = ""
lblClassAverage Result.Text = ""
txtStudentName. Focus()
End Sub
End Class
Nov 21 '05 #1
1 1323
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(myAr rayList(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 frmRyanStudentG rades
Inherits System.Windows. Forms.Form
'Define instance variables
Dim m_intCounter As Integer = 0
Dim m_strDisplayInf o(,) 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.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() 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.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'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 lblClassAverage Result As System.Windows. Forms.Label
Friend WithEvents lstNameGradeDis play 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.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.fraInputGrad e = New System.Windows. Forms.GroupBox
Me.lblStudentNa me = 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.lblClassAver age = New System.Windows. Forms.Label
Me.lblClassAver ageResult = New System.Windows. Forms.Label
Me.lstNameGrade Display = New System.Windows. Forms.ListBox
Me.txtStudentNa me = 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.btnSubmitGra de = New System.Windows. Forms.Button
Me.btnStartOver = New System.Windows. Forms.Button
Me.fraInputGrad e.SuspendLayout ()
Me.SuspendLayou t()
'
'fraInputGrade
'
Me.fraInputGrad e.Controls.Add( Me.btnStartOver )
Me.fraInputGrad e.Controls.Add( Me.btnSubmitGra de)
Me.fraInputGrad e.Controls.Add( Me.txtTest3)
Me.fraInputGrad e.Controls.Add( Me.txtTest2)
Me.fraInputGrad e.Controls.Add( Me.txtTest1)
Me.fraInputGrad e.Controls.Add( Me.txtStudentNa me)
Me.fraInputGrad e.Controls.Add( Me.lblTest3)
Me.fraInputGrad e.Controls.Add( Me.lblTest2)
Me.fraInputGrad e.Controls.Add( Me.lblTest1)
Me.fraInputGrad e.Controls.Add( Me.lblStudentNa me)
Me.fraInputGrad e.Location = New System.Drawing. Point(8, 8)
Me.fraInputGrad e.Name = "fraInputGr ade"
Me.fraInputGrad e.Size = New System.Drawing. Size(256, 208)
Me.fraInputGrad e.TabIndex = 0
Me.fraInputGrad e.TabStop = False
Me.fraInputGrad e.Text = "Input Grade"
'
'lblStudentName
'
Me.lblStudentNa me.Location = New System.Drawing. Point(8, 31)
Me.lblStudentNa me.Name = "lblStudentName "
Me.lblStudentNa me.Size = New System.Drawing. Size(80, 23)
Me.lblStudentNa me.TabIndex = 0
Me.lblStudentNa me.Text = "Student Name:"
'
'lblTest1
'
Me.lblTest1.Loc ation = New System.Drawing. Point(8, 63)
Me.lblTest1.Nam e = "lblTest1"
Me.lblTest1.Siz e = New System.Drawing. Size(40, 23)
Me.lblTest1.Tab Index = 1
Me.lblTest1.Tex t = "Test 1:"
'
'lblTest2
'
Me.lblTest2.Loc ation = New System.Drawing. Point(8, 91)
Me.lblTest2.Nam e = "lblTest2"
Me.lblTest2.Siz e = New System.Drawing. Size(40, 23)
Me.lblTest2.Tab Index = 2
Me.lblTest2.Tex t = "Test 2:"
'
'lblTest3
'
Me.lblTest3.Loc ation = New System.Drawing. Point(8, 119)
Me.lblTest3.Nam e = "lblTest3"
Me.lblTest3.Siz e = New System.Drawing. Size(40, 23)
Me.lblTest3.Tab Index = 3
Me.lblTest3.Tex t = "Test 3:"
'
'lblClassAverag e
'
Me.lblClassAver age.Location = New System.Drawing. Point(272, 184)
Me.lblClassAver age.Name = "lblClassAverag e"
Me.lblClassAver age.Size = New System.Drawing. Size(88, 23)
Me.lblClassAver age.TabIndex = 4
Me.lblClassAver age.Text = "Class Average:"
Me.lblClassAver age.TextAlign =
System.Drawing. ContentAlignmen t.MiddleLeft
'
'lblClassAverag eResult
'
Me.lblClassAver ageResult.Borde rStyle =
System.Windows. Forms.BorderSty le.Fixed3D
Me.lblClassAver ageResult.Locat ion = New System.Drawing. Point(424, 184)
Me.lblClassAver ageResult.Name = "lblClassAverag eResult"
Me.lblClassAver ageResult.Size = New System.Drawing. Size(56, 23)
Me.lblClassAver ageResult.TabIn dex = 4
Me.lblClassAver ageResult.TextA lign =
System.Drawing. ContentAlignmen t.MiddleCenter
'
'lstNameGradeDi splay
'
Me.lstNameGrade Display.Locatio n = New System.Drawing. Point(280, 16)
Me.lstNameGrade Display.Name = "lstNameGradeDi splay"
Me.lstNameGrade Display.Size = New System.Drawing. Size(200, 160)
Me.lstNameGrade Display.TabInde x = 5
Me.lstNameGrade Display.TabStop = False
'
'txtStudentName
'
Me.txtStudentNa me.Location = New System.Drawing. Point(96, 32)
Me.txtStudentNa me.Name = "txtStudentName "
Me.txtStudentNa me.Size = New System.Drawing. Size(152, 20)
Me.txtStudentNa me.TabIndex = 4
Me.txtStudentNa me.Text = ""
Me.txtStudentNa me.TextAlign =
System.Windows. Forms.Horizonta lAlignment.Righ t
'
'txtTest1
'
Me.txtTest1.Loc ation = New System.Drawing. Point(192, 64)
Me.txtTest1.Max Length = 3
Me.txtTest1.Nam e = "txtTest1"
Me.txtTest1.Siz e = New System.Drawing. Size(56, 20)
Me.txtTest1.Tab Index = 5
Me.txtTest1.Tex t = ""
Me.txtTest1.Tex tAlign = System.Windows. Forms.Horizonta lAlignment.Righ t
'
'txtTest2
'
Me.txtTest2.Loc ation = New System.Drawing. Point(192, 92)
Me.txtTest2.Max Length = 3
Me.txtTest2.Nam e = "txtTest2"
Me.txtTest2.Siz e = New System.Drawing. Size(56, 20)
Me.txtTest2.Tab Index = 6
Me.txtTest2.Tex t = ""
Me.txtTest2.Tex tAlign = System.Windows. Forms.Horizonta lAlignment.Righ t
'
'txtTest3
'
Me.txtTest3.Loc ation = New System.Drawing. Point(192, 120)
Me.txtTest3.Max Length = 3
Me.txtTest3.Nam e = "txtTest3"
Me.txtTest3.Siz e = New System.Drawing. Size(56, 20)
Me.txtTest3.Tab Index = 7
Me.txtTest3.Tex t = ""
Me.txtTest3.Tex tAlign = System.Windows. Forms.Horizonta lAlignment.Righ t
'
'btnSubmitGrade
'
Me.btnSubmitGra de.Location = New System.Drawing. Point(160, 176)
Me.btnSubmitGra de.Name = "btnSubmitGrade "
Me.btnSubmitGra de.Size = New System.Drawing. Size(88, 23)
Me.btnSubmitGra de.TabIndex = 8
Me.btnSubmitGra de.Text = "Submit Grade"
'
'btnStartOver
'
Me.btnStartOver .Enabled = False
Me.btnStartOver .Location = New System.Drawing. Point(8, 176)
Me.btnStartOver .Name = "btnStartOv er"
Me.btnStartOver .TabIndex = 9
Me.btnStartOver .Text = "Start Over"
'
'frmRyanStudent Grades
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(496, 221)
Me.Controls.Add (Me.lstNameGrad eDisplay)
Me.Controls.Add (Me.fraInputGra de)
Me.Controls.Add (Me.lblClassAve rage)
Me.Controls.Add (Me.lblClassAve rageResult)
Me.Name = "frmRyanStudent Grades"
Me.Text = "Ryan Student Grades"
Me.fraInputGrad e.ResumeLayout( False)
Me.ResumeLayout (False)

End Sub

#End Region

Private Sub btnSubmitGrade_ Click(ByVal sender As System.Object, ByVal e
As System.EventArg s) 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", MessageBoxButto ns.OK, MessageBoxIcon. Error)
Else
'Go through array cases
m_intCounter += 1
Select Case m_intCounter
Case Is = 1
m_strDisplayInf o(m_intCounter, 0) = strStudentName
m_strDisplayInf o(m_intCounter, 1) = AverageGrade()
Case Is = 2
m_strDisplayInf o(m_intCounter, 0) = strStudentName
m_strDisplayInf o(m_intCounter, 1) = AverageGrade()
Case Is = 3
m_strDisplayInf o(m_intCounter, 0) = strStudentName
m_strDisplayInf o(m_intCounter, 1) = AverageGrade()
Case Is = 4
m_strDisplayInf o(m_intCounter, 0) = strStudentName
m_strDisplayInf o(m_intCounter, 1) = AverageGrade()
Case Is = 5
m_strDisplayInf o(m_intCounter, 0) = strStudentName
m_strDisplayInf o(m_intCounter, 1) = AverageGrade()
Case Is = 6
m_strDisplayInf o(m_intCounter, 0) = strStudentName
m_strDisplayInf o(m_intCounter, 1) = AverageGrade()
Case Is = 7
m_strDisplayInf o(m_intCounter, 0) = strStudentName
m_strDisplayInf o(m_intCounter, 1) = AverageGrade()
Case Is = 8
m_strDisplayInf o(m_intCounter, 0) = strStudentName
m_strDisplayInf o(m_intCounter, 1) = AverageGrade()
Case Is = 9
m_strDisplayInf o(m_intCounter, 0) = strStudentName
m_strDisplayInf o(m_intCounter, 1) = AverageGrade()
Case Is = 10
m_strDisplayInf o(m_intCounter, 0) = strStudentName
m_strDisplayInf o(m_intCounter, 1) = AverageGrade()
btnSubmitGrade. Enabled = False
btnStartOver.En abled = True
End Select
'Display data, reset focus to the top
txtStudentName. Focus()
lstNameGradeDis play.Items.Add( strStudentName & ControlChars.Ta b
& AverageGrade())
lblClassAverage Result.Text = String.Format(" {0:F}",
TotalAverage())
End If
End Sub
Function TotalAverage() As Double
'Define Variables
Dim dblClassAverage As Double
dblClassAverage = m_strDisplayInf o(m_intCounter, 1)
Return (dblClassAverag e / m_intCounter)
End Function
Function AverageGrade() As Decimal
'Function to average the 3 test grades
'Define Variables
Dim decTest1 As Decimal = Val(txtTest1.Te xt)
Dim decTest2 As Decimal = Val(txtTest2.Te xt)
Dim decTest3 As Decimal = Val(txtTest3.Te xt)
Dim decAverage As Decimal
decAverage = decTest1 + decTest2 + decTest3
Return (decAverage / 3)
End Function

Private Sub btnStartOver_Cl ick(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnStartOver.Cl ick
'Starts the program over
m_intCounter = 0
btnSubmitGrade. Enabled = True
btnStartOver.En abled = False
lstNameGradeDis play.Items.Clea r()
txtStudentName. Text = ""
txtTest1.Text = ""
txtTest2.Text = ""
txtTest3.Text = ""
lblClassAverage Result.Text = ""
txtStudentName. Focus()
End Sub
End Class

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
3045
by: Jatinder | last post by:
I 'm a professional looking for the job.In interview these questions were asked with some others which I answered.But some of them left unanswered.Plz help. Here are some questions on C/C++, OS internals? Q1 . What is the use of pointer to an array? Q2 . What is the use of array of pointers? Q3 . What is the use of pointer to function ? Q4 . How to print through serial port? What is Flow Control(Xon,Xoff) ?
7
1024
by: MattB | last post by:
Can anyone recommend a good host for a small site (<10 mb - low traffic) and a pop account? There are so many options out there it's hard to choose. In the past I've used llamacom.com which is very affordable ($7.95/Month) and reliable, but they do not have any asp.net support. If they did they would be ideal. Alas. TIA! Matt
7
2346
by: | last post by:
I need some help on a project that connects to a secure web server using basic authentication and a Base64 encoded userid and password, and posts a urlencoded xml file.
17
2551
by: Student | last post by:
Hi All, I have an assignment for my Programming language project to create a compiler that takes a C++ file as input and translate it into the C file. Here I have to take care of inheritance and operator overloading and virtual functions. I mean it should not hamper the C++ meaning. In frank and simple terms i need to implement a small C++ compiler in C++, and i want the intermediate representation to be C. Please help me in this....
0
32152
by: Jobs | last post by:
All answers to the below interview questions are at http://www.geocities.com/dotnetinterviews/ or you can download the complete answer zip file from http://www.questpond.com/ProjectManagementInterviewQuestions.zip What is project management?
2
7230
by: freepdfforjobs | last post by:
Full eBook with 4000 C#, JAVA,.NET and SQL Server Interview questions http://www.questpond.com/SampleInterviewQuestionBook.zip Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip
4
2052
by: =?Utf-8?B?VzFsZDBuZTc0?= | last post by:
When one architects a new project one of the first steps in the decision is to decide on the layers. (In my opinion anyway) One architecture that I have used before is to go solid OO and create objects, which normally are very small and only deals with the stuff pertaining to that object, then break it down into Business Process, Process Controllers and Data Access Objects for each "Object", each of which is created in it's very own .Net...
169
9238
by: JohnQ | last post by:
(The "C++ Grammer" thread in comp.lang.c++.moderated prompted this post). It would be more than a little bit nice if C++ was much "cleaner" (less complex) so that it wasn't a major world wide untaking to create a toolchain for it. Way back when, there used to be something called "Small C". I wonder if the creator(s) of that would want to embark on creating a nice little Small C++ compiler devoid of C++ language features that make...
6
1119
by: =?Utf-8?B?Qm9ucw==?= | last post by:
I'm not exactly sure how to state this problem. One of my students emailed me that when she tries to open a web page through IE it opens small and she has to hit the maximize button to make it the correct size. I know I've seen this on other puters but don't know what causes it. I'm sure it's some setting....but have looked at all of mine and can't figure out what it could be. I've had great luck in the past with questions and am hoping...
0
9918
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
11060
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10697
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10786
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7097
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5762
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5959
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4578
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4175
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.