Answer to Question #267950 in Visual Basic for ray

Question #267950

  create

1. MainMenu form having :

a) button Open Answers File. When button is clicked; open Answer.txt, and read and

store the answers in an array of Strings. Close this file.

b) 2nd  button Open Student Responses File. When button is clicked, do following: i. Open StudentResponses.txt file.

ii. Read number of students who sat the exam value and store it a variable.

iii. Then use loop to read student’s responses to questions. This loop runs up to number of students who sat the exam value read in i). For each line read, split record into an Exam Structure array that has an ID and responses field.

c) button titled Open Student Details File. When this button is clicked, do following:

a) Open and read StudentDetails.txt and store data into a StudentDetails structure array.

d) button titled Display Grades Results when clicked, should open up another form titled Grades Results Sheet on which in label should display grades results for class



1
Expert's answer
2021-11-18T06:56:00-0500
Imports System.IO


Public Class MainForm
    Structure Exam
        Public ID As String
        Public responses() As String
    End Structure




    Structure StudentDetails
        Public StudentID As String
        Public FirstName As String
        Public LastName As String
        Public Country As String
        Public Responses As String
    End Structure


    Private answers(100) As String
    Private student_Details() As StudentDetails
    Private totalStudentDetails As Integer = 0


    Private Sub btnOpenAnswersFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenAnswersFile.Click
        Dim line As String
        Dim FilePath As String = "Answer.txt"
        Using reader As StreamReader = New StreamReader(FilePath)
            ' Read one line from file
            line = reader.ReadLine()
        End Using
        Dim c As Integer = 0
        For Each l In line
            answers(c) = l
            c += 1
        Next
    End Sub


    Private Sub btnOpenStudentResponsesFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenStudentResponsesFile.Click


        Dim FilePath As String = "StudentResponses.txt"


        Using reader As StreamReader = New StreamReader(FilePath)
            ' Read the number of students who sat the exam value and store it a variable.
            Dim numberStudents As Integer = Integer.Parse(reader.ReadLine())
            Dim exams(numberStudents - 1) As Exam
            'Then use a loop to read the student’s responses to the questions. 
            'This loop runs up to the number of students who sat the exam value read in 
            ' For each line read, split the record into ID# and responses and store in ID and Responses array or into an 
            'Exam Structure array that has an ID and responses field. 
            For i As Integer = 0 To numberStudents - 1
                Dim values() = reader.ReadLine().Split(",")
                exams(i).ID = values(0)
                ReDim exams(i).responses(19)
                Dim c As Integer = 0
                For Each l In values(1)
                    exams(i).responses(c) = l
                    c += 1
                Next
            Next
            reader.Close()
        End Using


    End Sub


    Private Sub btnOpenStudentDetailsFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenStudentDetailsFile.Click


        Dim FilePath As String = "StudentDetails.txt"
        Using reader As StreamReader = New StreamReader(FilePath)
            ' Read the number of students 
            Dim numberStudents As Integer = Integer.Parse(reader.ReadLine())
            ReDim student_Details(numberStudents - 1)
            For i As Integer = 0 To numberStudents - 1
                Dim values() = reader.ReadLine().Split(",")
                student_Details(i).StudentID = values(0)
                student_Details(i).FirstName = values(1)
                student_Details(i).LastName = values(2)
                student_Details(i).Country = values(3)
                student_Details(i).Responses = values(4)
                totalStudentDetails += 1
            Next
            reader.Close()
        End Using
        
    End Sub
    ''' <summary>
    ''' 'd) button titled Display Grades Results when clicked, 
    ''' should open up another form titled Grades Results Sheet on which in label should display grades results for class
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnDisplayGradesResults_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplayGradesResults.Click


        If totalStudentDetails <> 0 Then
            Dim _DisplayGradesResultsForm As New DisplayGradesResultsForm(student_Details)
            _DisplayGradesResultsForm.ShowDialog()
        End If
        
    End Sub


    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub
End Class










Public Class DisplayGradesResultsForm






    Sub New(ByVal student_Details As MainForm.StudentDetails())
        ' TODO: Complete member initialization 
        InitializeComponent()
        txtReport.Text = ""
        For i As Integer = 0 To student_Details.Length - 1
            txtReport.Text += "Student ID: " + student_Details(i).StudentID + vbNewLine
            txtReport.Text += "First Name: " + student_Details(i).FirstName + vbNewLine
            txtReport.Text += "Last Name: " + student_Details(i).LastName + vbNewLine
            txtReport.Text += "Country: " + student_Details(i).Country + vbNewLine
            txtReport.Text += "Responses: " + student_Details(i).Responses + vbNewLine + vbNewLine
        Next
    End Sub






    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Close()
    End Sub
End Class






Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS