Answer to Question #267964 in Visual Basic for ray

Question #267964

how to code button titled Open Student Details File.

When this button is clicked, do following: a) Open and read StudentDetails.txt and store the data into a StudentDetails structure array. 


1
Expert's answer
2021-11-20T06:41:38-0500
Imports System.IO




Public Class MainForm
  



    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 student_Details() As StudentDetails
    Private totalStudentDetails As Integer = 0







    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
 



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