Question: From Starting Out with Visual Basic 2012, Chapter 9, Programming Challenges, #3 Student Test Scores: Below is my latest attempt to calculate and display the

From Starting Out with Visual Basic 2012, Chapter 9, Programming Challenges, #3 Student Test Scores:

Below is my latest attempt to calculate and display the average test scores. Can you help me get all 6 average test scores. I would really appreciate the help. I feel like a dog chasing its tail! And I have a terrible headache. Here is a table that shows the form layout:

txtName1

txtS11

txtS12

txtS13

txtS14

txtS15

lblAvg1

txtName2

txtS21

txtS22

txtS23

txtS24

txtS25

lblAvg2

txtName3

txtS31

txtS32

txtS33

txtS34

txtS35

lblAvg3

txtName4

txtS41

txtS42

txtS43

txtS44

txtS45

lblAvg4

txtName5

txtS51

txtS52

txtS53

txtS54

txtS55

lblAvg5

txtName6

txtS61

txtS62

txtS63

txtS64

txtS65

lblAvg6

A button: Calculate Averages

I dont get any of the average scores:

Imports System.IO

Public Class Form1

Private Sub mnuFileExit_Click(sender As Object, e As EventArgs) Handles mnuFileExit.Click

' Close form

Me.Close()

End Sub

Private Sub btnCalculatAverages_Click(sender As Object, e As EventArgs) Handles btnCalculatAverages.Click

StudentScoreDataInput()

End Sub

End Class

Module StudentTestScoresModule

Const intMAX_SUBSCRIPT_STUDENT As Integer = 6

Const intMAX_SUBSCRIPT_STUDENT_SCORES As Integer = 5

'create structure

Public Structure StudentData

Dim strName As String

Dim dblTestScoresArray() As Double

Dim dblAverage As Double

End Structure

Dim StudentsArray(intMAX_SUBSCRIPT_STUDENT) As StudentData

Dim dblTotalStd1 As Double

Sub StudentNameDataInput()

StudentsArray(0).strName = Form1.txtName1.Text

StudentsArray(1).strName = Form1.txtName2.Text

StudentsArray(2).strName = Form1.txtName3.Text

StudentsArray(3).strName = Form1.txtName4.Text

StudentsArray(4).strName = Form1.txtName5.Text

StudentsArray(5).strName = Form1.txtName6.Text

End Sub

Sub StudentScoreDataInput()

Dim dblAverage(intMAX_SUBSCRIPT_STUDENT) As Double

Dim dblTotal As Double

For intIndex = 0 To intMAX_SUBSCRIPT_STUDENT

ReDim StudentsArray(intIndex).dblTestScoresArray(intMAX_SUBSCRIPT_STUDENT_SCORES)

Next

'initialize test scores for first student in the array

StudentsArray(0).dblTestScoresArray(0) = CDbl(Form1.txtS11.Text)

StudentsArray(0).dblTestScoresArray(1) = CDbl(Form1.txtS12.Text)

StudentsArray(0).dblTestScoresArray(2) = CDbl(Form1.txtS13.Text)

StudentsArray(0).dblTestScoresArray(3) = CDbl(Form1.txtS14.Text)

StudentsArray(0).dblTestScoresArray(4) = CDbl(Form1.txtS15.Text)

'initialize test scores for second student in the array

StudentsArray(1).dblTestScoresArray(0) = CDbl(Form1.txtS21.Text)

StudentsArray(1).dblTestScoresArray(1) = CDbl(Form1.txtS22.Text)

StudentsArray(1).dblTestScoresArray(2) = CDbl(Form1.txtS23.Text)

StudentsArray(1).dblTestScoresArray(3) = CDbl(Form1.txtS24.Text)

StudentsArray(1).dblTestScoresArray(4) = CDbl(Form1.txtS25.Text)

'initialize test scores for 3rd student in the array

StudentsArray(2).dblTestScoresArray(0) = CDbl(Form1.txtS31.Text)

StudentsArray(2).dblTestScoresArray(1) = CDbl(Form1.txtS32.Text)

StudentsArray(2).dblTestScoresArray(2) = CDbl(Form1.txtS33.Text)

StudentsArray(2).dblTestScoresArray(3) = CDbl(Form1.txtS34.Text)

StudentsArray(2).dblTestScoresArray(4) = CDbl(Form1.txtS35.Text)

'initialize test scores for 4th student in the array

StudentsArray(3).dblTestScoresArray(0) = CDbl(Form1.txtS41.Text)

StudentsArray(3).dblTestScoresArray(1) = CDbl(Form1.txtS42.Text)

StudentsArray(3).dblTestScoresArray(2) = CDbl(Form1.txtS43.Text)

StudentsArray(3).dblTestScoresArray(3) = CDbl(Form1.txtS44.Text)

StudentsArray(3).dblTestScoresArray(4) = CDbl(Form1.txtS45.Text)

'initialize test scores for 5th student in the array

StudentsArray(4).dblTestScoresArray(0) = CDbl(Form1.txtS51.Text)

StudentsArray(4).dblTestScoresArray(1) = CDbl(Form1.txtS52.Text)

StudentsArray(4).dblTestScoresArray(2) = CDbl(Form1.txtS53.Text)

StudentsArray(4).dblTestScoresArray(3) = CDbl(Form1.txtS54.Text)

StudentsArray(4).dblTestScoresArray(4) = CDbl(Form1.txtS55.Text)

'initialize test scores for 6th student in the array

StudentsArray(5).dblTestScoresArray(0) = CDbl(Form1.txtS61.Text)

StudentsArray(5).dblTestScoresArray(1) = CDbl(Form1.txtS62.Text)

StudentsArray(5).dblTestScoresArray(2) = CDbl(Form1.txtS63.Text)

StudentsArray(5).dblTestScoresArray(3) = CDbl(Form1.txtS64.Text)

StudentsArray(5).dblTestScoresArray(4) = CDbl(Form1.txtS65.Text)

For Each i As StudentData In StudentsArray

dblTotal = 0 'initialize to 0 for each student

For Each S As Double In i.dblTestScoresArray

dblTotal += S

Next

'set the average for the current student

i.dblAverage = dblTotalStd1 / intMAX_SUBSCRIPT_STUDENT_SCORES

Next

'now set the values in the lables

Form1.lblAvg1.Text = (StudentsArray(0).dblAverage.ToString)

Form1.lblAvg2.Text = (StudentsArray(1).dblAverage.ToString)

Form1.lblAvg3.Text = (StudentsArray(2).dblAverage.ToString)

Form1.lblAvg4.Text = (StudentsArray(3).dblAverage.ToString)

Form1.lblAvg5.Text = (StudentsArray(4).dblAverage.ToString)

Form1.lblAvg6.Text = (StudentsArray(5).dblAverage.ToString)

End Sub

End Module

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!