473,554 Members | 4,738 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 1306
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
3011
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 ?...
7
1012
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
2336
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
2520
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++...
0
32084
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
7174
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...
4
2038
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...
169
8958
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...
6
1106
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...
0
7620
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...
0
7541
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7821
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. ...
0
8057
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...
1
7586
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...
0
7900
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6172
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5452
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
861
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.