Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

'This is the program for computing students test score average and save them in a file specified and generate a report from the file saved

'This is the program for computing students test score average and save them in a file specified and generate a report from the file saved Imports System.IO Imports System.IO.FileStream 'Class name MyStudentTestScores. Public Class Form1 Public Class MyStudentTestScores 'Declaration of variables Dim(6) As MyStudent 'Define the function IsValid() to check the scores whether it falls within the range of 0 and 100 'Function is valid Public Function IsValid(ByVal score As Integer) As Integer 'If the scores are within the range 0 and 100 If score >= 0 And score <= 100 Then Return (score) Else Return ("Please Try Again!") End If End Function End Class Private Sub BtnAverage_Click(sender As Object, e As EventArgs) Handles BtnAverage.Click 'For loop to iterate through the student scores For inc1 = 0 To 5 sender(inc1) = New MyStudent() ReDim (inc1).tScores(4) Next 'Try block Try 'Student one's scores sender(0).sName = TB1.Text sender(0).tScores(0) = IsValid(Convert.ToInt32(TB11.Text)) sender(0).tScores(1) = IsValid(Convert.ToInt32(TB12.Text)) sender(0).tScores(2) = IsValid(Convert.ToInt32(TB13.Text)) sender(0).tScores(3) = IsValid(Convert.ToInt32(TB14.Text)) sender(0).tScores(4) = IsValid(Convert.ToInt32(TB15.Text)) 'Student two's scores sender(1).sName = TB2.Text sender(1).tScores(0) = IsValid(Convert.ToInt32(TB21.Text)) sender(1).tScores(1) = IsValid(Convert.ToInt32(TB22.Text)) sender(1).tScores(2) = IsValid(Convert.ToInt32(TB23.Text)) sender(1).tScores(3) = IsValid(Convert.ToInt32(TB24.Text)) sender(1).tScores(4) = IsValid(Convert.ToInt32(TB25.Text)) 'Student three's scores sender(2).sName = TB3.Text sender(2).tScores(0) = IsValid(Convert.ToInt32(TB31.Text)) sender(2).tScores(1) = IsValid(Convert.ToInt32(TB32.Text)) sender(2).tScores(2) = IsValid(Convert.ToInt32(TB33.Text)) sender(2).tScores(3) = IsValid(Convert.ToInt32(TB34.Text)) sender(2).tScores(4) = IsValid(Convert.ToInt32(TB35.Text)) 'Student four's scores sender(3).sName = TB4.Text sender(3).tScores(0) = IsValid(Convert.ToInt32(TB41.Text)) sender(3).tScores(1) = IsValid(Convert.ToInt32(TB42.Text)) sender(3).tScores(2) = IsValid(Convert.ToInt32(TB43.Text)) sender(3).tScores(3) = IsValid(Convert.ToInt32(TB44.Text)) sender(3).tScores(4) = IsValid(Convert.ToInt32(TB45.Text)) 'Student five's scores sender(4).sName = TB5.Text sender(4).tScores(0) = IsValid(Convert.ToInt32(TB51.Text)) sender(4).tScores(1) = IsValid(Convert.ToInt32(TB52.Text)) sender(4).tScores(2) = IsValid(Convert.ToInt32(TB53.Text)) sender(4).tScores(3) = IsValid(Convert.ToInt32(TB54.Text)) sender(4).tScores(4) = IsValid(Convert.ToInt32(TB55.Text)) 'Student six' scores sender(5).sName = TB6.Text sender(5).tScores(0) = IsValid(Convert.ToInt32(TB61.Text)) sender(5).tScores(1) = IsValid(Convert.ToInt32(TB62.Text)) sender(5).tScores(2) = IsValid(Convert.ToInt32(TB63.Text)) sender(5).tScores(3) = IsValid(Convert.ToInt32(TB64.Text)) sender(5).tScores(4) = IsValid(Convert.ToInt32(TB65.Text))

Catch ex As Exception MessageBox.Show("Enter a Value within 0 & 100!") End Try 'For loop to iterate through the six students For in1 = 0 To 5 sender(inc1).sAverage = 0 'For loop to calculate average scores for the six students Next For inc2 = 0 To 4 sender(inc1).sAverage += sender(inc1).tScores(inc2) 'End of inner loop Next sender(inc1).sAverage /= 5 'End of outer loop 'Displaying the average scores for the students in their repective text boxes TBAVG1.Text = sender(0).sAverage.ToString("n2") TBAVG2.Text = sender(1).sAverage.ToString("n2") TBAVG3.Text = sender(2).sAverage.ToString("n2") TBAVG4.Text = sender(3).sAverage.ToString("n2") TBAVG5.Text = sender(4).sAverage.ToString("n2") TBAVG6.Text = sender(5).sAverage.ToString("n2") 'For loop to iterate through the six students For inc1 = 0 To 5 Dim stdRecord As String stdRecord = s(inc1).sName 'For loop to get the records of the six students For inc2 = 0 To 4 stdRecord += "" + s(inc1).tScores(inc2).ToString("n2") 'End of inner For loop Next stdRecord += "" + (inc1).sAverage.ToString() 'End of outer loop Next End Sub

Private Sub SaveMenuItem_Click(sender As Object, e As EventArgs) Handles SaveMenuItem.Click 'Declaration of variable for the name of the file Dim nameOfFile As String = InputBox("Enter filename:", "Filename prompt", "TestScores.txt") 'Declaration of variable for saving the file Dim saveFile As IO.StreamWriter = IO.File.CreateText(nameOfFile) 'For loop to save the students details in the specified file For i = 0 To 5 'Saves the name of the students saveFile.WriteLine(s(i).sName) 'Save the scores saveFile.WriteLine(s(i).tScores(0)) saveFile.WriteLine(s(i).tScores(1)) saveFile.WriteLine(s(i).tScores(2)) saveFile.WriteLine(s(i).tScores(3)) saveFile.WriteLine(s(i).tScores(4)) 'Saves the averages of the students saveFile.WriteLine(s(i).sAverage) Next 'Closes the specified file saveFile.Close() 'On Successful Saving of file, show this message MessageBox.Show(nameOfFile & "File successfully created!", "DONE") End Sub

Private Sub GenerateReportMenuItem_Click(sender As Object, e As EventArgs) Handles GenerateReportMenuItem.Click 'Declaration of variable to generate report Dim reportString As String = "" 'To loop to iterate through the students details to generate the report For i = 0 To 5 'So the report will show names reportString &= s(i).SName & vbTab 'So the report shows scores reportString &= s(i).tScores(0) & vbTab reportString &= s(i).tScores(1) & vbTab reportString &= s(i).tScores(2) & vbTab reportString &= s(i).tScores(3) & vbTab reportString &= s(i).tScores(4) & vbTab 'So the report shows averages reportString &= s(i).sAverage & vbNewLine Next 'Message box showing the report MessageBox.Show(reportString, "Report")

End Sub

Private Sub HelpMenuItem_Click(sender As Object, e As EventArgs) Handles HelpMenuItem.Click 'Show help details in the form if MessageBox MessageBox.Show(vbTab + vbTab + "Student Test Scores" + vbNewLine + vbNewLine + "This is a project to compute the student average test scores in a specified file and generate a report of the scores and average") End Sub End Class Public Class MyStudent 'Attribute name Public Property sName() As String 'Attribute test scores Public tScores() As Integer 'Attribute average Public Property sAverage() As Decimal End Class

Im getting errors all over the place. This is my code for visual basic 2015 please help !!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Flash XML Applications Use AS2 And AS3 To Create Photo Galleries Menus And Databases

Authors: Joachim Schnier

1st Edition

0240809173, 978-0240809175

More Books

Students also viewed these Databases questions