Answer to Question #267647 in Visual Basic for ray

Question #267647

how to code :

that a button titled Open Student Responses File. When this button is clicked, do the following: i. Open StudentResponses.txt file. ii. Read the number of students who sat the exam value and store it a variable. iii. 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 i). 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. 


1
Expert's answer
2021-11-17T13:23:37-0500
Imports System.IO


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




    Private answers(100) As String
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load






    End Sub


    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
End Class



<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    '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.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.btnOpenAnswersFile = New System.Windows.Forms.Button()
        Me.btnOpenStudentResponsesFile = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'btnOpenAnswersFile
        '
        Me.btnOpenAnswersFile.Location = New System.Drawing.Point(12, 33)
        Me.btnOpenAnswersFile.Name = "btnOpenAnswersFile"
        Me.btnOpenAnswersFile.Size = New System.Drawing.Size(183, 28)
        Me.btnOpenAnswersFile.TabIndex = 0
        Me.btnOpenAnswersFile.Text = "Open Answers File"
        Me.btnOpenAnswersFile.UseVisualStyleBackColor = True
        '
        'btnOpenStudentResponsesFile
        '
        Me.btnOpenStudentResponsesFile.Location = New System.Drawing.Point(201, 33)
        Me.btnOpenStudentResponsesFile.Name = "btnOpenStudentResponsesFile"
        Me.btnOpenStudentResponsesFile.Size = New System.Drawing.Size(183, 28)
        Me.btnOpenStudentResponsesFile.TabIndex = 0
        Me.btnOpenStudentResponsesFile.Text = "Open Student Responses File"
        Me.btnOpenStudentResponsesFile.UseVisualStyleBackColor = True
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(399, 94)
        Me.Controls.Add(Me.btnOpenStudentResponsesFile)
        Me.Controls.Add(Me.btnOpenAnswersFile)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub
    Friend WithEvents btnOpenAnswersFile As System.Windows.Forms.Button
    Friend WithEvents btnOpenStudentResponsesFile As System.Windows.Forms.Button

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